in reply to Is there an equivalent $. for lists or arrays in map or foreach?

The usual idiom is:
my @ARRAY = (...); my @result = map { do something with $_ and $ARRAY[$_] } 0..$#ARRAY;
Then, $_ is giving you the index of the element, and you indirect it to get to the element itself.

-- Randal L. Schwartz, Perl hacker
Be sure to read my standard disclaimer if this is a reply.

  • Comment on •Re: Is there an equivalent $. for lists or arrays in map or foreach?
  • Download Code

Replies are listed 'Best First'.
Re^2: Is there an equivalent $. for lists or arrays in map or foreach?
by bsdz (Friar) on Sep 16, 2004 at 17:01 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