in reply to hash and while
Because each iterates over each key and value and keys and values reset that iterator back to the beginning.
You want to get the value of keys before you iterate through the hash with each:
my %hash = qw( a 1 b 2 ); my $count = 0; my $key_count = keys %hash; while ( my ( $key, $value ) = each %hash ) { $count++ if $value == $key_count; } print $count;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: hash and while
by Anonymous Monk on Aug 05, 2010 at 07:06 UTC | |
by AnomalousMonk (Archbishop) on Aug 05, 2010 at 12:26 UTC |