Let me say this yet again: What you're asking about is how to create symbolic references; ie, how to manipulate variables' names programatically (variable variable names). Perl allows you to do this. But it is broadly regarded as the wrong way to accomplish what you actually need to do. You're better off using proper references, specifically, a list of lists. You can read about how to do that in perlref, perlreftut, perllol, and perldsc.
Many newcomers think that they've come up with one of those situations where symbolic references are a good idea. They're almost universally wrong. Computer Science has developed for a half of a century in a direction that separates a program's data from the program's source itself. Variable variable names (symbolic references) muddle that distinction, possibly with unhappy results. While there are a few useful uses of symbolic references, symbol table manipulation is best left to a few experts. Just as you don't need to know how to build a microprocessor in order to use a microprocessor, you don't need to worry about manipulating the symbol table in order to benefit from its existence. To be frank, you haven't come up with a new good reason to use symbolic references. It's been addressed, rehashed, and meditated upon. The problem's been solved.
So when you feel the temptation to write, "@array1" and "@array2", or @{$array . $i}, you should instead be doing something like this:
$array->[1][4] # for a multidimensional array
Symbolic references are illegal under "use strict;", for good reason. They are error prone, and the errors they foster can be very difficult to pinpoint, and in fact, not always immediately apparent. You may not discover an error caused by misuse of symbolic references until code has been in place for a long time. Then one day you'll stumble across that special case that awakens the demon. Other times, the bugs can crop up immediately, but be extremely difficult to figure out where the offending code is.
Proper references (hard references) are easier to manage, and in most regards, more powerful. They are the basis for complex datastructures in Perl, and usually the facilitators of objects in Perl as well. They're very flexible, and yet, they don't blur the distinction between code and data, and they are unlikely to produce the kind of hard to find bugs that soft refrences can hide.
Dave
In reply to Re: adding number to array name
by davido
in thread adding number to array name
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |