@main::match_to_array
仅输出数组@match_to_array
中的最后一个元素,而不是整个数组。使用main ::打印显示其所有元素的数组变量。
我参考this SO link参考了我的代码。
输入HTML由 [email protected] [email protected] [email protected] [email protected] [email protected]
#!/usr/bin/perl –w
use strict;
use warnings;
use Cwd;
sub extractMail {
my $perl_path = cwd;
# Full HTML.htm
if(-e 'test.html') {
open(OPENFILE, "$perl_path/test.html") or die "Unable to open file";
}
my @email = <OPENFILE>;
close OPENFILE;
foreach my $email (@email){
if ($email =~ /regex to match data/{
my $match = "$1\n";
our @match_to_array = split ("\n",$match);
} # end of if statement
} # end of foreach
} # end of subroutine extractMail
for (my $a = 1;$a<=1;$a++){
&extractMail;
print @main::match_to_array;
}
感谢您的答复。 “全局符号”有一个错误$ OPENFILE“需要显式包名”。我试着换成'我们的$ OPENFILE',然后使用'$ main :: OPENFILE',它不起作用。 – iridescent 2013-05-07 08:35:30
除了'@ ISA'或应模块的要求(例如'我们的@ EXPORT_OK')之外,不应该使用'our'',并且根本没有理由使用或'$ main ::'。停止使用它们。忘掉它们。你走错了方向。 – ikegami 2013-05-07 10:20:28
注意到@ikegami。 – iridescent 2013-05-07 13:45:46