in reply to Re^2: Array loops and assignments
in thread Array loops and assignments
Definitely overcomplicating it. Try this idiom: Think of a hash as a namespace, and its elements as variables within that namespace.
my @array = qw( Larry Curly Moe ); my %stooges; @stooges{ @array } = ( 0 .. $#array ); print "$_ = $stooges{$_}\n" for keys %stooges;
Or if you want numbers in the name:
%stooges = map { 'var' . $_ , $array[$_] } 0 .. $#array;
Dave
|
|---|