【问题标题】:Can I access __DATA__ section in mac os x automator我可以访问 mac os x automator 中的 __DATA__ 部分吗
【发布时间】:2015-09-24 13:43:39
【问题描述】:

我正在尝试在自动机内部运行的 perl 脚本中使用 __DATA__ 部分。

当作为 shell 脚本运行时,一切都很好,但在 automator 内部,数据部分看起来像是空的。

知道为什么,以及比拥有巨大的“此处”文件更好的解决方法吗?

编辑

示例脚本

use strict;
use warnings;
while(<DATA>){
    print $_;
}
__DATA__
line1
line2
line3

【问题讨论】:

  • 你能提供一个工作样本吗?
  • 不是很懂接近票。这是一个有效的问题。投票结束,只是因为有人对Automator一无所知是可惜的。无论如何,编辑问题 - 并添加一个示例。
  • perl 在程序启动时相当于open DATA, '&lt;', $0seek DATA, $data_start, 0。我不知道 Automator 对此做了什么,但您可以尝试编写 seek DATA, 0, 0; print while &lt;DATA&gt;; 并查看是否获得源代码输出。还值得添加 CHECK {print tell(DATA), "\n"; } 并检查使用和不使用 Automator 的输出是否相同

标签: perl automator


【解决方案1】:

Automator.app 运行您的脚本

/usr/bin/perl -e 'your script here' --

因此__DATA__ 句柄不起作用。


EDIT如何确定

  • Automator.app 按定义运行 /usr/bin/perl,因此:
  • /usr/bin/perl 重命名为/usr/bin/perl_ORIG
  • 在其位置添加了另一个 perl 脚本(其他 perl),+chmod 755
#!/opt/local/bin/perl
use strict;
use warnings;

my $n = 0;
print "$0\n";
for my $arg (@ARGV) {
        print "$n:[$arg]\n";
        $n++;
}
  • 在 Automator 中运行原始脚本
  • 在输出中,假的“perl”准确地显示了直到-- 的所有参数

不是很好(也不正确) - 但有助于发现 Automator 如何运行脚本,例如它使用-e(小写)、script content + --

此外,tell DATA 在 Automator 中返回 0,在正常脚本中它返回文件中的实际位置。 (见鲍罗丁的评论)

【讨论】:

  • 不错的调查——你是怎么确定的?
  • @MarkSetchell 使用的方法不是很正确,(请参阅编辑)但帮助... :)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-05-03
  • 2016-01-24
  • 2014-09-28
  • 2021-10-04
  • 2016-02-29
  • 1970-01-01
相关资源
最近更新 更多