in reply to Create an array reference from a string

While it is possible to do what you say that you want in Perl, it is not advisable. Please read Mark Jason Dominus' excellent Why it's stupid to `use a variable as a variable name' about it. Most likely, you do want real references or a hash instead.

  • Comment on Re: Create an array reference from a string

Replies are listed 'Best First'.
Re: Re: Create an array reference from a string
by xorl (Deacon) on Apr 12, 2004 at 19:37 UTC
    So I guess you're suggesting something like:
    my @bar = qw(One Two Three); my $foo = "bar"; my %quux = ("bar", \@bar); print "***" . $foo . "***"; foreach my $baz (@{$quux{$foo}}) { print $baz . "\n\n"; }
    It looks like that will work, but it does mean I have to create a hash.
      Think about it this way - you are asking to access some data structure (scalar, array, hash, whatever) using an arbitrary string as its name. That is the very definition of a hash.

      In fact, soft references are implemented under the hood as a hash. So, it's not like you're saving anything. :-)

      ------
      We are the carpenters and bricklayers of the Information Age.

      Then there are Damian modules.... *sigh* ... that's not about being less-lazy -- that's about being on some really good drugs -- you know, there is no spoon. - flyingmoose