Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: subroutine reference parameters

by choroba (Canon)
on Jun 03, 2011 at 14:18 UTC ( #907985=note: print w/ replies, xml ) Need Help??


in reply to subroutine reference parameters

each returns two things, key and value. You only assign to $key. You probably wanted to use keys instead? Or this:

sub printElement { my ($key,$val) = @_; print $key,' ',$val,"\n"; } my %hash = (0 => 'a', 1 => 'b', 2 => 'c'); while(my ($key,$value) = each(%hash)) { &printElement($key, $value); }


Comment on Re: subroutine reference parameters
Download Code
Re^2: subroutine reference parameters
by gnosti (Friar) on Jun 04, 2011 at 01:38 UTC
    Hi,

    You posted a link to the documentation for 'each'. Perhaps you should re-read it! When called in scalar context, the function returns a key. When called in list context, it returns a key-value pair.

      OK, but ($key) = is not scalar context.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (7)
As of 2015-07-06 23:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (85 votes), past polls