in reply to Peek a hash without breaking iterator
A simple way to work around each would be to load it into an array and simulate each as follows:
Update: you could also create an oo version of each that uses a handler object instead of magic so that it can't break under your circumstances. e.g.$ perl -e ' > my %h=(qw(a b c d e f)); > { my @each = %h; > while (my $k = shift @each) { > my $v = shift @each; > print "$k => $v\n"; > }}' c => d e => f a => b
package OOEach; sub new { my ($class) = @_; return bless {}, $class; } sub each { my $self = shift; $self->{queue} ||= [@_]; # note: will only init once my $k = shift @{$self->{queue}}; my $v = shift @{$self->{queue}}; return ($k, $v); } ;
One world, one people
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Peek a hash without breaking iterator
by Anonymous Monk on Jun 21, 2016 at 09:18 UTC | |
by anonymized user 468275 (Curate) on Jun 21, 2016 at 10:30 UTC | |
by Anonymous Monk on Jun 21, 2016 at 12:13 UTC |