Michael G Schwern:
# You can do it with a map without much trouble:
#
# my @indexes = map { /condition/ ? $i++ : () } @stuff;
Unless I'm mistaken, that won't work, since $i only gets incremented on
matches. I think this:
my @indexes = map { $i++; /condition/ ? $i : () } @stuff;
Will work fine, though.
Or, in the spirit of use-a-foreach-like-a-for (and my favorite WTDI):
my @indexes = grep { $stuff[$_] =~ /condition/ } 0..$#stuff;
As you might guess, I'm a (not very vocal) proponent of adding a way to
get at a foreach's (or map's or grep's) current index. (Hmm, can this
be done with XS? Must research...)
# Its so rare that you work by array index in Perl. Usually
# things flow together element by element. Sort of like how
Funny, I tend to find myself working by-element fairly often, usually
when I have to remove elements in the middle of a loop--something Perl
doesn't like. :^( (Not that I don't understand *why* Perl doesn't
allow it--just that it can be an inconvenience.)
# you rarely handle strings character by character which can
# severely confuse C programmers.
Well, that's a silly way of working anyway. ;^)
--Brent Dax <[EMAIL PROTECTED]>
@roles=map {"Parrot $_"} qw(embedding regexen Configure)
"If you want to propagate an outrageously evil idea, your conclusion
must be brazenly clear, but your proof unintelligible."
--Ayn Rand, explaining how today's philosophies came to be