steph_bow has asked for the wisdom of the Perl Monks concerning the following question:


Hello, I would like to use a variable such as below, and the name of this variable depends on another variable.

Is that allowed or is there any better way ? Thanks
my @TARGET =(0..50); foreach $target(@TARGET){ my $M4_${target}; }

Replies are listed 'Best First'.
Re: good use of variables
by Corion (Patriarch) on Jul 19, 2007 at 13:35 UTC
Re: good use of variables
by syphilis (Archbishop) on Jul 19, 2007 at 15:55 UTC
    Heh ... couldn't help but notice that Corion's advice (which is sound) is only a couple of typos away:
    my @TARGET =(0..50); foreach $target(@TARGET){ $M4_{$target}; }
    Cheers,
    Rob

      The my is still required, but stuck in front of $target. ;)


      DWIM is Perl's answer to Gödel