我需要一些指導以及下面的Perl代碼。當我離開no strict 'refs'
時,sub
正常工作。但是,如果no strict 'refs'
被刪除,然後我得到的錯誤信息:Perl不能使用字符串作爲符號ref,而嚴格參考
Can't use string ("A") as a symbol ref while "strict refs" in use at test.pl
它死在了線標記爲「在這裏」的。此sub
需要打開(寫入>)A..Z中的所有文件,並根據READ文件(LOG)中的regex
將輸出寫入相應的文件輸出。
use strict;
use Text::CSV_XS;
no strict 'refs';
...
...
sub file_split {
my ($i, $fh, @FH);
my ($file) = @_;
my (@alpha) = ("A".."Z");
for (@alpha) {
$fh = $_ ;
open ($fh,">","$_-$file") || die $!; <--------- HERE
push @FH, $fh;
}
my $csv = Text::CSV_XS->new({ binary => 1,
allow_whitespace => 1,
allow_loose_escapes => 1,
allow_loose_quotes =>1,
escape_char => undef ,
sep_char => ',',
auto_diag=> 1
});
open(LOG,"<", $file) || die $!;
while (my $row = $csv->getline(*LOG)) {
if ($row->[0] =~ /^(\w)/) {
print $1 <--------- HERE
"$row->[0]".",".
"$row->[1]" .",".
"$row->[2]" .",".
"$row->[3]" .",".
"$row->[4]".",".
"$row->[5]"."\n";
} else {
print "Record skipped... --> $row->[0] <-- ... please verify \n";
}
}
}
這個技巧。並且打印$ 1被替換爲打印{$ FH {$ 1}}。謝謝。 – Marcello