in reply to Create an array reference from a string
What you're talking about is known as "symbolic references". It won't work on lexical ("my") variables; your @bar would have to be a package (aka "global") variable.
But while symbolic refs can be done, they are strongly discouraged. Instead, consider using a hash variable:
my %h; @{$h{"bar"}} = qw( One Two Three ); $foo = "bar"; for ( @{ $h{$foo} } ) {
jdporter
The 6th Rule of Perl Club is -- There is no Rule #6.
|
|---|