
davorg
Thaumaturge
/ Moderator
Dec 31, 2002, 2:24 AM
Post #3 of 3
(262 views)
|
|
Re: [yaniv_av] Manipulating arrays by variables
[In reply to]
|
Can't Post
|
|
The process of using a variable as the name of another variable is called a "symbolic reference" and it's a very bad idea for many reasons which have been explained very well in these three articles. It suggest you read those before going any further. In fact symbolic references as such a bad idea that when you put "use strict" at the top of your program (and you really should be doing that) one of the effects is to explicitly prevent you from using symbolic references. A better way to do things like this is usually to use a hash. In your case I'd do something like this:
my %arrays; $arrays{A} = [0, 1, 2]; my @tmp = ('group', 'A'); print @{$arrays{$tmp[1]}}; -- Dave Cross, Perl Hacker, Trainer and Writer http://www.dave.org.uk/ Get more help at Perl Monks
|