Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Re: subroutine reference parameters

by choroba (Bishop)
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); }

Replies are listed 'Best First'.
Re^2: subroutine reference parameters
by gnosti (Hermit) on Jun 04, 2011 at 01:38 UTC

    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?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://907985]
[Discipulus]: ok.. where to look to serve a webpage composed by parts that fill themseves indipendently over time? no auto updates, just different times like (for a domain name) ip resolution, whois infos, lwp check ..

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (9)
As of 2017-11-23 08:40 GMT
Find Nodes?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:

    Results (332 votes). Check out past polls.