in reply to Peek a hash without breaking iterator

If your debugger is incompatible with the 'each' magic, then the options are: use a different debugger, or don't use each.

A simple way to work around each would be to load it into an array and simulate each as follows:

$ 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
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.
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
    Heheh, another one , hurricup is creating the debugger, hes writing the debugger, he cannot change the users code to suit the debugger,
      Actually he IS changing the user's code to effect debugging. As I understand it he is effectively inserting a command to copy the hash into the code he is debugging. So in fact a custom implementation of each is still one way to stop the real one breaking.

      One world, one people

        How? Code is running, enter inside loop, hash copy resets iterator. Too late for simulation. You mean add simulator before loop, through magic, before its needed because its ok to reset iterator at that point? How many frames back is safe? Too much overhead?