@main::match_to_array
仅打印出数组中的最后一个元素,@match_to_array
而不是整个数组。
我参考这个 SO 链接做了我的代码。
输入 HTML 包括
dmit@sp.com
ems@es.com
dew@es.com
dmit@sp.com
erg@es.com
#!/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;
}