in reply to Passing Reference of a Hash to a method

You were assigning a list of arguments to a scalar, which was a scalar of the number of arguments ("1"). The ref of a non-reference is blank. Try this:

sub traverseHash { my $hRef=shift; print ref($hRef); }

Replies are listed 'Best First'.
Re^2: Passing Reference of a Hash to a method
by davorg (Chancellor) on Nov 24, 2004 at 06:34 UTC

    Er... no. If the original poster was assigning a list to a scalar, then the behaviour of the comma operator would ensure that he ended up with the last element in the list in the scalar variable - which would have been what he wanted.

    my $scalar = ('this', 'is', 'a', 'list'); print $scalar; # prints 'list'

    The problem was caused because he was assigning an array, not a list.

    Please read What is the difference between a list and an array? from perlfaq4 which explains this difference in more detail.

    --
    <http://www.dave.org.uk>

    "The first rule of Perl club is you do not talk about Perl club."
    -- Chip Salzenberg