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

Hi!
(Sorry for my bad english :)

Question:
Exist file, content list phrases. Each from this phrases should be array name. Example:

phrases:
abacus
qwerty

$a = 'abacus';
$b = 'qwerty';

I would like:
@abacus
@qwerty

How made this?
@$a ? wrong?

Thx, Chewby

Replies are listed 'Best First'.
Re: Array names
by httptech (Chaplain) on May 10, 2000 at 15:42 UTC
    You'd probably be much better off using a hash here.
    $hash{'abacus'} = ([1,2,3,4,5]); $hash{'querty'} = ([6,7,8,9,10]);
    So then $hash{'abacus'} and $hash{'qwerty'} are array references you can read like:
    print $hash{'abacus'}[0]; # Prints "1" print $hash{'qwerty'}[1]; # Prints "7"
    Then you also have the advantage of easy access to all your array "names" by using keys %hash
      Ok. It's worked.
      But this is hash, no array :(

      How me made this use array?

      Thx, Chewby
        It's actually a hash of arrays. That is, it is like a standard hash, but instead of the values being scalars, they are array references:
        my %data = ( 'abacus' => [ 1, 2, 3, 4, 5], 'qwerty' => [ 5, 4, 3, 2, 1]);
        This way, you can refer to the arrays by name without having to use symbolic references (you can store array names in variables, and use those variables as keys to the hash -- that will prevent some subtle errors).

        See perlref and perldsc for more information. It's a very powerful technique.

RE: Array names
by muppetBoy (Pilgrim) on May 10, 2000 at 12:11 UTC
    This appears to work ok:
    $a ='string1'; @$a[0] = 'string2'; print @string1;
    What exactly is your problem?
    Addition:oops - Note however that this will not work if you have
    use strict;
    which is always a good idea.
    I would examine why you want to write your code in this way as I am sure there is a 'better' way of doing it.
    If you could show more of your code I/we could probably give you a better answer.