此脚本从下载的网页中提取 url。我在使用这个脚本时遇到了一些问题——当我使用"my $csv_html_line = @_ ;"
然后打印出来时"@html_LineArray"
——它只是打印出来"1's"
。当我用脚本替换时
"my $csv_html_line = @_ ;"
工作"my $csv_html_line = shift ;"
正常。我不知道两者之间有什么区别"= @_" and shift
-因为我认为在没有指定某些内容的情况下,在子例程中, shift shift froms"@_".
#!/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) ;
}