Variável especial Perl "@_" em uma sub-rotina não está funcionando
Esse script retira os URLs de uma página da Web baixada. Eu tive alguns problemas com esse script - quando eu uso o"my $csv_html_line = @_ ;"
e depois imprima o"@html_LineArray"
- apenas imprime"1's"
. Quando eu substituo o"my $csv_html_line = @_ ;"
com"my $csv_html_line = shift ;"
o script funciona bem. Eu não sei qual é a diferença entre o"= @_" and shift
- porque eu pensei que, sem especificar algo, em uma sub-rotina, o turno do turno"@_".
#!/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) ;
}
É isso que as impressões acima são impressas.
1
1
1
1
1
1
1
1
1
1
1
1
Isso funciona bem - ele usa o turno em vez de "@_"
#!/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) ;
}