One of the effects of use strict; is to disable the use of Symbolic references, which is exactly what you are trying to do. In general, using symbolic references are a bad idea - most of the things you would do with a symbolic reference can be done more effectively with a hash (or, in this case, a hash of arrays). Please read Why it's stupid to use a variable as a variable name - this is required reading before getting into this stuff.

Like I mentioned above, the natural way to do this is usually a hash of arrays (or HoA). This is actually a hash of array references. See perlreftut, perllol, perlref, and/or perldsc. Your code might look like:

#!/usr/bin/perl use strict; use warnings; my %hoa = (names => ['joe', 'bob', 'sally'] ); print join ", ", @{$hoa{names}};

If you actually have a good reason to do what you say, you still need to consider the following from Symbolic references:

Only package variables (globals, even if localized) are visible to symbolic references. Lexical variables (declared with my()) aren't in a symbol table, and thus are invisible to this mechanism.

This means you cannot declare your @names array with my, but either must declare it with an explicit package or initialize it without strict in place. Something like:

#!/usr/bin/perl use strict; my $array_name = 'names'; @main::names = ('joe', 'bob', 'sally'); DISABLE_BLOCK: { # localizes disabling strict no strict 'refs'; print join ", ", @{$array_name}; }

In reply to Re: using input as array name by kennethk
in thread using input as array name by calmthestorm

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.