in reply to Re^4: Hash value interpolation
in thread Hash value interpolation

local $\ = "\n"; my %h = map { $_ => 1 } qw( a b c d ); for my $pass (1..3) { print "Pass $pass:"; while (my ($k,$v) = each %h) { print $k; last if $pass == 1; } }
Pass 1: c Pass 2: a <---- 'c' missing b d Pass 3: c a b d
Solution:
local $\ = "\n"; my %h = map { $_ => 1 } qw( a b c d ); for my $pass (1..3) { print "Pass $pass:"; keys %h; # Reset iterator while (my ($k,$v) = each %h) { print $k; last if $pass == 1; } }
Pass 1: c Pass 2: c <---- Welcome back a b d Pass 3: c a b d

Replies are listed 'Best First'.
Re^6: Hash value interpolation
by Anonymous Monk on Feb 18, 2009 at 22:24 UTC
    ikegami thanks again for all the help and explanations