What you are trying to do is to use Symbolic references (also called 'soft references'; see perlref). This is a Bad Thing and produces only package (i.e., global) variables, but for better or worse, here it is:
>perl -wMstrict -MData::Dumper -le "my @array_names = qw(foo baz); for my $array_name (@array_names) { no strict 'refs'; @$array_name = ( reverse split '', $array_name ); } print Data::Dumper->Dump([\@::foo, \@::baz], [qw(*foo *baz)]); " Name "main::foo" used only once: possible typo at -e line 1. Name "main::baz" used only once: possible typo at -e line 1. @foo = ( 'o', 'o', 'f' ); @baz = ( 'z', 'a', 'b' );
perlref and other documentation linked below explain why symbolic/soft references are Bad. (Don't worry about the  Name "what::ever" used only once... warnings; they'll be the least of your problems.)

A far better approach is to use a hash with 'hard' references to anonymous arrays:

>perl -wMstrict -MData::Dumper -le "my @key_names = qw(foo baz); my %hash; for my $key_name (@key_names) { $hash{$key_name} = [ reverse split '', $key_name ]; } print Data::Dumper->Dump([$hash{$_}], [qq{hash{$_}}]) for @key_names; " $hash{foo} = [ 'o', 'o', 'f' ]; $hash{baz} = [ 'z', 'a', 'b' ];
Again, see perlref, perlreftut, perldsc and perllol for extensive info.

In reply to Re: naming array from a scalar by AnomalousMonk
in thread naming array from a scalar by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.