in reply to iterating 2 arrays in parallel

Or even shorter:
my @array1=(one, two, three); my @array2=(1, 2, 3); my @combined; map {push @combined,"$_:$array2[$counter++]"} @array1;'

Cheers - Pat

Replies are listed 'Best First'.
Re^2: iterating 2 arrays in parallel
by ikegami (Patriarch) on Apr 15, 2009 at 15:42 UTC

    map { push ... } is a rather silly construct. Better solutions:

    my $counter = 0; my @combined; push @combined, "$_:$array2[$counter++]" for @array1;
    my $counter = 0; my @combined = map { "$_:$array2[$counter++]" } @array1;

    Having two independent but equivalent iterators is overly complex. Better:

    my @combined = map { "$array1[$_]:$array2[$_]" } 0..$#array1;