UPDATE: The answer was found with eval (see my response to mreece).

I'm trying to make an array of arrays, the member arrays of which have variable names. This variable-ness of the array names is necessary (unless someone has a better idea - I'm definitely open to it) because the array(s) to be used are specified at runtime by the user using Getopt::Std. The array names can't be predefined because they are being pulled from a datafile of arrays, which I don't own, that is auto-generated and could at any time have arrays added/deleted/renamed. Obviously, I don't want to rewrite with each new array, so variable names it is. Here's the issue. When I take the list of arrays specified on the command line, and add them to a new array, the new array stores their names as strings instead of simply importing the arrays' entries. Example: Here is what it would look like if I explicitly named them without variables: (much of the assumed stuff has been extracted)

use Getopt::Std; require "/path/filename"; # Here's my datafile. getopts('f:'); #Here's the part I'd like to have create my array of arrays #if ( $opt_f ) { # chomp $opt_f ; # @combined = $opt_f; # The offending line. #} #Here's what would work, if only the names weren't variable @combined = ( @array1,@array2); foreach $entry ( @combined ) { print "return: $entry \n"; }
If Getopt is bringing in $opt_f which is a string "@array1,@array2,@et_cetera", how can I get it to work properly in my "@combined..." statement? I've RTFM, and I'm sure the answer's there, but I've spent way too much time on this particular issue.

In reply to Array of Arrays with Variable Names by JWM

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.