in reply to Re: Using foreach to process a hash
in thread Using foreach to process a hash

while (($key, $value) = each %hash) {

You got three things wrong:

  1. use while, not foreach
  2. the pair returned by each is $key,$value not $value,$key
  3. you need parentheses around ($key,$value)

But of course, if he wants to use foreach, then for completeness it's fair to remind that he can do so, but in connection with keys, not each:

foreach my $key (keys %hash) { my $value=$hash{$key};

Update: hadn't noticed it already been covered by imp's reply. Hopefully repetita iuvant

Replies are listed 'Best First'.
Re^3: Using foreach to process a hash
by jdporter (Paladin) on Oct 22, 2006 at 13:27 UTC

    Yes, but that had already been covered by imp's reply.