How do I pass a hash to a function in Perl?

后端 未结 9 947
囚心锁ツ
囚心锁ツ 2020-12-24 05:36

I have a function that takes a variable and an associative array, but I can\'t seem to get them to pass right. I think this has something to do with function declarations, h

9条回答
  •  伪装坚强ぢ
    2020-12-24 06:10

    Alternatively:

    sub PrintAA
    {
        my $test       = shift;
        my %aa         = @_;
            print $test . "\n";
            foreach (keys %aa)
            {
                    print $_ . " : " . $aa{$_} . "\n";
                    $aa{$_} = $aa{$_} . "+";
            }
    }
    

    The thing you're fundamentally missing is that an associative array isn't a single argument (though an associative array reference is, as in Paul Tomblin's answer).

提交回复
热议问题