Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: Passing Reference of a Hash to a method

by rrwo (Friar)
on Nov 23, 2004 at 18:25 UTC ( [id://409953]=note: print w/replies, xml ) Need Help??


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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://409953]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (None)
    As of 2025-01-18 13:21 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      Which URL do you most often use to access this site?












      Results (56 votes). Check out past polls.