in reply to naming array from a scalar
perlref and other documentation linked below explain why symbolic/soft references are Bad. (Don't worry about the Name "what::ever" used only once... warnings; they'll be the least of your problems.)>perl -wMstrict -MData::Dumper -le "my @array_names = qw(foo baz); for my $array_name (@array_names) { no strict 'refs'; @$array_name = ( reverse split '', $array_name ); } print Data::Dumper->Dump([\@::foo, \@::baz], [qw(*foo *baz)]); " Name "main::foo" used only once: possible typo at -e line 1. Name "main::baz" used only once: possible typo at -e line 1. @foo = ( 'o', 'o', 'f' ); @baz = ( 'z', 'a', 'b' );
A far better approach is to use a hash with 'hard' references to anonymous arrays:
Again, see perlref, perlreftut, perldsc and perllol for extensive info.>perl -wMstrict -MData::Dumper -le "my @key_names = qw(foo baz); my %hash; for my $key_name (@key_names) { $hash{$key_name} = [ reverse split '', $key_name ]; } print Data::Dumper->Dump([$hash{$_}], [qq{hash{$_}}]) for @key_names; " $hash{foo} = [ 'o', 'o', 'f' ]; $hash{baz} = [ 'z', 'a', 'b' ];
|
|---|