此脚本从下载的网页中剔除网址。我在使用这个脚本时遇到了一些麻烦 - 当我使用"my $csv_html_line = @_ ;"
然后打印出"@html_LineArray"
- 它只打印出"1's"
。当我用"my $csv_html_line = shift ;"
替换 "my $csv_html_line = @_ ;"
时,该脚本正常工作。 我不知道有什么区别betweeh的"= @_" and shift
- 监守我认为 没有指定的东西,在一个子程序,SHIFT SHIFT 320交织"@_".
子例程中的Perl特殊变量“@_”无法正常工作
#!/usr/bin/perl
use warnings;
use strict ;
sub find_url {
my $csv_html_line = @_ ;
#my $csv_html_line = shift ;
my @html_LineArray = split("," , $csv_html_line) ;
print "@html_LineArray\n" ;
#foreach my $split_line(@html_LineArray) {
# if ($split_line =~ m/"adUrl":"(http:.*)"/) {
# my $url = $1;
# $url =~ tr/\\//d;
# print("$url\n") ;
# }
#}
}
my $local_file = "@ARGV" ;
open(my $fh, '<', "$local_file") or die "cannot open up the $local_file $!" ;
while(my $html_line = <$fh>) {
#print "$html_line\n";
find_url($html_line) ;
}
这就是上面会打印出来。
1
1
1
1
1
1
1
1
1
1
1
1
这工作得很好 - 它使用换档而不是“@_”
#!/usr/bin/perl
use warnings;
use strict ;
sub find_url {
#my $csv_html_line = @_ ;
my $csv_html_line = shift ;
my @html_LineArray = split("," , $csv_html_line) ;
#print "@html_LineArray\n" ;
foreach my $split_line(@html_LineArray) {
if ($split_line =~ m/"adUrl":"(http:.*)"/) {
my $url = $1;
$url =~ tr/\\//d;
print("$url\n") ;
}
}
}
my $local_file = "@ARGV" ;
open(my $fh, '<', "$local_file") or die "cannot open up the $local_file $!" ;
while(my $html_line = <$fh>) {
#print "$html_line\n";
find_url($html_line) ;
}
http://stackoverflow.com/questions/2126365/whats-the -disference-between-my-variablename-and-my-variablename-in-perl – mob