Re: Perl hashrefs and 'each' function

by John Erjavec V <jev(at)pconline.com>

 Date:  Thu, 24 Feb 2000 22:50:37 -0600
 To:  David Mintz <mambomintz(at)yahoo.com>,
hwg-languages(at)hwg.org
 In-Reply-To:  yahoo
  todo: View Thread, Original
At 10:58 AM 2/24/00 -0800, David Mintz wrote:
>I was wondering if/how you can use the 'each' function
>with a hash reference instead of a hash, i.e., how
>doing you do this:
>
>     while ( ($key, $value) = each(%hash) ) {
>
>       print "The value of $key is $value\n"
>     }
>
>with a $hashref rather than %hash.
>
>You get an error when you try to use $hashref as an
>argument to each because Perl wants a hash.

Just dereference the has reference.  To do that, just create a block that 
is the right datatype, and wrap the hashref in it, like 
so:  %{$hashref}.  You can also write that like %$hashref.  Hope that 
helps.

-JEV
--
John Erjavec V  ##  spammers-will-be-reported(at)jevonline.com
                 ##  http://www.jevonline.com/jev/index.html
"I'll say it again for the logic impaired."  --Larry Wall

HWG: hwg-languages mailing list archives, maintained by Webmasters @ IWA