我可以在mac os x automator中访问__DATA__部分吗?

时间:2015-07-07 07:26:40

标签: perl automator

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

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

任何关于为什么的想法,以及一个更好的解决方法,而不是拥有一个巨大的"在这里"文件?

修改

示例脚本

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

1 个答案:

答案 0 :(得分:1)

The Automator.app runs your script as

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

therefore the __DATA__ handle doesn't works.


EDIT how to determined

  • the Automator.app runs by definition /usr/bin/perl, so:
  • renamed the /usr/bin/perl to /usr/bin/perl_ORIG
  • added another perl script in its place (other 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++;
}
  • runs the original script in the Automator
  • on the output the fake "perl" shows exactly all arguments up to --

Not very nice (nor correct) - but helped to discover how the Automator runs the scripts, e.g. it uses the -e (lowercase), script content + --.

Also, the tell DATA returns 0 in the Automator, in the normal script it return the real position in the file. (see Borodin's comment)