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

Is there the equivalent of $. ($INPUT_LINE_NUMBER) for lists or arrays that can be used in a map or foreach construct, e.g.
my @f = ('%s', '%.2f', '%u','%d'); my @d = ('my string', '123456.54321' ,'1234.4321' , '1234'); my @D = map { sprintf($f[$LIST_INDEX], $_) } @d; print @D,"\n";
I would like something like $LIST_INDEX to exist. Is there an alternative concise way of doing what I would like to do?

Replies are listed 'Best First'.
•Re: Is there an equivalent $. for lists or arrays in map or foreach?
by merlyn (Sage) on Sep 16, 2004 at 16:55 UTC
      that's precisely what I was hoping for, the following change makes the original code work.
      my @D = map { sprintf($f[$_], $d[$_]) } 0..$#d;
      Thank you
Re: Is there an equivalent $. for lists or arrays in map or foreach? (mapcar!)
by tye (Sage) on Sep 16, 2004 at 18:36 UTC