Perl-Spezialvariable "@_" in einem Unterprogramm funktioniert nicht

Dieses Skript entfernt die URLs von einer heruntergeladenen Webseite. Ich hatte einige Probleme mit diesem Skript - wenn ich das @ benut"my $csv_html_line = @_ ;" und dann das @ ausdruck"@html_LineArray" - druckt nur aus"1's". Wenn ich das @ erset"my $csv_html_line = @_ ;" mit"my $csv_html_line = shift ;" Das Skript funktioniert gut. Ich weiß nicht, was der Unterschied zwischen dem @ i"= @_" and shift - weil ich dachte, dass in einem Unterprogramm ohne Angabe von etwas Verschiebung von"@_".

#!/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) ;
}

Dies ist es, was oben ausgedruckt wird.

1
1
1
1
1
1
1
1
1
1
1
1

Dies funktioniert gut - es wird die Verschiebung anstelle von "@_" verwendet

#!/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) ;
}

Antworten auf die Frage(4)

Ihre Antwort auf die Frage