in reply to Transforming a for loop to a more functional approach?

I think you are trying to create a hash where the second array element becomes a key and the first element becomes its value; and so on for fourth and third elements, etc. In that case, try this:

my @list = qw(a b c d e f g h); my %hash = reverse @list; print map { "$_ -> $hash{$_}\n" } keys %list; #Prints: h -> g b -> a d -> c f -> e

But note that both methods complain if your array length is odd.

Replies are listed 'Best First'.
Re^2: Transforming a for loop to a more functional approach?
by bellaire (Hermit) on Mar 03, 2009 at 11:14 UTC
    ++, I gave my answer right before bed, and then laying there in the dark I thought, "Oh, duh, reverse it into a hash!" :)... Much better.