Maybe something like this?
my @one = ('$apple', '$pear'); my $two = '$orange'; eval "$one[0] = 'hello'"; # evaluates $apple = 'hello' eval "$two = 'goodbye'"; # evaluates $orange = 'goodbye' print "$apple $orange"; # hello goodbye
(Note the single quotes in '$apple' etc. With double quotes, the (empty) global variable $apple would be interpolated.)
Update: Another way would be to use symbolic references:
use strict; use warnings; my @one = qw($apple $pear); my $two = '$orange'; our ($apple, $pear, $orange); { no strict 'refs'; ${substr $one[0],1} = 'hello'; # ${'apple'} = 'hello'; ${substr $two,1} = 'goodbye'; # ${'orange'} = 'goodbye'; } print "$apple $orange"; # hello goodbye
(You'd need package variables and no strict 'refs' in this case, though)
In reply to Re^3: Reading and producing variable lists (w/o hashes!)
by almut
in thread Reading and producing variable lists (w/o hashes!)
by bingohighway
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |