ramziabboud has asked for the wisdom of the Perl Monks concerning the following question:

I am looping through a hash: foreach $key (sort (keys(%myHash))) { ##some code; } Can I send control back to the top of the loop without advancing an element in myHash? To say it another way, can i run ##some code; again with the same $key value? Does something like a back; exist?

Replies are listed 'Best First'.
Re: Backing up in a foreach loop.
by ikegami (Patriarch) on Feb 14, 2007 at 21:13 UTC
    As mentioned in the ChatterBox, you want redo.
    foreach $key (sort (keys(%myHash))) { ... if (condition) { # Start over without advancing. # $key retains its current value. redo; } ... }
Re: Backing up in a foreach loop.
by japhy (Canon) on Feb 14, 2007 at 21:12 UTC