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};
}
|