in reply to Automatic Loop Counter not in perl

You've got some illegal syntax in %LoH->[$count]. But presuming I know what you meant, here's a nestable, localized-loop-counter-providing loop function that handles most of your wants, without* being too awkward:
use strict; use warnings; sub counted_for (&@) { local our $LOOPCOUNT=-1; my $sub = shift; for (@_) { ++$LOOPCOUNT; $sub->(); } } # Define a modestly complicated structure to loop through my $LoH; my $count = 3; @{$LoH->[$count]}{'a'..'e'} = (); my @y = ('X'..'Z'); counted_for { print "$LOOPCOUNT: $_\n"; counted_for { print " $LOOPCOUNT $_\n" } keys %{$LoH->[$count]}; } @y;
*arguably; because prototypes require that non-explicit subs be the first arg, I can't duplicate the for syntax, and of course I can't make a predicate form. Maybe it should be a map replacement instead.

Update: And of course last and next won't work with it.will give you warnings.


Caution: Contents may have been coded under pressure.