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.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.