此腳本從下載的網頁中剔除網址。我在使用這個腳本時遇到了一些麻煩 - 當我使用"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