JWM has asked for the wisdom of the Perl Monks concerning the following question:
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)
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.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"; }
|
|---|