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
    awsome!!!!
    just one question.. there must be iterator variable... do u no which is that???
    Thanks

      Each hash has its own iterator variable, but this variable is not explicitly accessible to humble monks such as you and I. No doubt a way may be found through inline C code or perhaps through tie, but other, more subtle and puissant monks must assist you in this.