in reply to Re^2: Reading and producing variable lists (w/o hashes!)
in thread Reading and producing variable lists (w/o hashes!)

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)

Replies are listed 'Best First'.
Re^4: Reading and producing variable lists (w/o hashes!)
by why_bird (Pilgrim) on May 01, 2009 at 10:31 UTC
    oo crazy cool.. Two questions though: what might be a 'good' place to use this? and does it run under 'strict'?
    ........
    Those are my principles. If you don't like them I have others.
    -- Groucho Marx
    .......
      and does it run under 'strict'?

      It would run under use strict, if you declare the variables, e.g.

      my ($apple, $pear, $orange); # lexicals # or our ($apple, $pear, $orange); # lexically scoped package variabl +es # or use vars qw($apple $pear $orange); # global package variables
      what might be a 'good' place to use this?

      There are almost certainly better ways to approach virtually any typical problem you might have... :)