我是一个Perl脚本编写者,我想向子例程传递一个输出文件的文件名。我尝试过以下方法:
use strict;
use warnings;
test("Output.dat");
sub test {
my $name = @_;
open(B, ">$name") or die "Failure \n";
print B "This is a test! \n";
close(B);
}
我将多次使用子程序,因此必须传递文件名,不能在子程序内部声明。
希望能对您有所帮助 :)
my ($name) = @_;
,另请参阅 http://perlmaven.com/scalar-and-list-context-in-perl - mpapec