[Nh-pm] Pesky darn hashes...

Erik Price erikprice at mac.com
Thu Sep 5 23:15:33 CDT 2002


On Thursday, September 5, 2002, at 11:27  PM, Ken Ambrose wrote:

> It's been a while since I used hashes, so I'm probably doing something
> woefully wrong.  But, why doesn't:
>
> while (<>){
> [...]
>     %addresses = ($biggaddr => $_);
> }
>
> foreach $key (sort keys %addresses){
>     print "$key = $addresses{$key}\n";
> }
>
> work? $bigaddr is an integer, if that makes any difference, and the
> "foreach" section was swiped bodily out of a Perl book o' mine.

I think what's happening is that the value of your hash is being 
reassigned at each point through your while loop.  Does this work 
better for you:

my %addresses;
while(<>) {
[...]
	$addresses{$bigaddr} = $_;
}



But I might be totally out of touch with what you're trying to do, in 
which case I apologize.


Erik





--
Erik Price

email: erikprice at mac.com
jabber: erikprice at jabber.org




More information about the Nh-pm mailing list