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

Dear monks,

I am working with a program in which some arrays must be accessed based on their names. I am experiencing a weird problem since some arrays can be accessed and others not.

The example below should give an impression of how the problem goes. I have some arrays defined on some data and named as "@descriptor_array_(some number)". Then I have other arrays, named as "@array_dummy_(some number)" which I construct with data read from files and some number crunching. The thing is that I must access these arrays recursively based on their names, and for doing that I use a reference of the type:

$name = sprintf "%s%s",'descriptor_array',$array_no; print @$name;

Well, the problem is that the predefined arrays cannot be accessed whereas the others can. Both types are defined using "my" within the main loop of the program, and the loop where I call these arrays has the instruction "no strict 'refs'"

Any thoughts???

UPDATE: $array_no is just an example, in my program the refernce is a string that I compose with sprintf.

my @descriptor_array1 = ( 1, 2, 3, 4 ); my @descriptor_array2 = ( 1, 2, 3, 4 ); my @descriptor_array3 = ( 1, 2, 3, 4 ); my @descriptor_array4 = ( 1, 2, 3, 4 ); .......................... my (@array_dummy1,@array_dummy2,@array_dummy3); foreach my $array_no(@insomearray) { no strict 'refs'; $name = sprintf "%s%s",'descriptor_array',$array_no; print @$name; # prints nothing! $name = sprintf "%s%s",'array_dummy',$array_no; print @$name; # prints "array_dummy! }