我正在尝试在自动机内部运行的perl脚本中使用__DATA__
部分。
当作为shell脚本运行时,一切都很好,但在automator中,数据部分看起来是空的。
任何关于为什么的想法,以及一个更好的解决方法,而不是拥有一个巨大的"在这里"文件?
示例脚本
use strict;
use warnings;
while(<DATA>){
print $_;
}
__DATA__
line1
line2
line3
答案 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
/usr/bin/perl
, so:/usr/bin/perl
to /usr/bin/perl_ORIG
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++;
}
--
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)