On Fri, Mar 22, 2002 at 11:21:24AM -0500, James Linden Rose, III wrote:
> Men and women of Perldom,
>
> Can somebody remind me of how you can take an array full of names and
> turn them into variable names?
% perl -mstrict -e 'my @x=qw(a b c);no strict q/vars/; my $i=0;$$_ = $i++ for @x;print
$a,$b,$c'
> Simplified from reality, I want to do something like this:
>
> $i = 0;
> foreach (@rray) {
> $$_ = $i;
> $i++;
> }
>
> Where the result is a variable named $name_1, $name_2, ... $name_n.
Assuming your code worked, it would create variables whose names were the
same as the array contents. so if:
@rray = qw(one two tres);
you'd have
$one=0; $two=1; $tres=2;
If you want the basename of the variable to stay the same, then I don't
understand what the array is doing here. All you need is the start and end
points of the numbers. and what the values should be. Is that the where the
array comes in?
-Gyepi
--
Optimism is no substitute for proper planning. -- me