in reply to Re: Trouble passing hash into function
in thread Trouble passing hash into function

That's what I thought would work but here is what's happening:
sub test_parser { use Data::Dumper; #print Dumper(@_); my %test = @_; print Dumper(%test); }
If I comment out the second print and uncomment the first print, the @_ dumps fine. When I try to set %test, I get this error:

Reference found where even-sized list expected at Debugger.pm line 8.
I'm sending the hash from a master .pl file into the function like this:

Debugger::test_parser(\%competitors_master);
What else could be wrong?

Thanks,

Doug

Replies are listed 'Best First'.
Re^3: Trouble passing hash into function
by GrandFather (Saint) on Sep 05, 2007 at 23:13 UTC

    You are passing a hash reference, not a hash (which gets flattened into a list).

    The first dump works as expected because it sees a list containing one element which is the reference to the hash you passed in.

    The my %test = @_; and generates an error because @_ contains only one element - the reference to the hash. Instead you should my $test = shift; and work with the reference.


    DWIM is Perl's answer to Gödel