in reply to Variable naming of Arrays
For all practical purposes, you could live happily with the assumption that it is impossible to do what you're asking. Decades of advances in computer science, and programming languages, have taken us to a point in history where it is virtually unnecessary to do so. And in fact, it actually is impossible in many powerful programming languages.
In actuality, Perl will let you tie yourself a noose. Perl will let you use "symbolic references" (which is what you're asking about). But until you have a thorough understanding of why not, you just shouldn't, and you probably don't need to.
The stock answer for this sort of question is to use a hash. Perl's package global variables reside in a glorified hash. If a hash is good enough for Perl, it should be good enough for your purposes too.
my %arrays; $arrays{bart} = [ 1, 2, 3, 4, 5 ]; $arrays{homer} = [ 80, 42, 33, 51, 0 ]; print $arrays{homer}[3], "\n";
See how easy it is to do the right thing? ;)
Dave
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Variable naming of Arrays
by stellagoddc (Novice) on May 12, 2006 at 16:08 UTC | |
by davorg (Chancellor) on May 12, 2006 at 16:14 UTC |