in reply to Creating variables for each array member
While this is possible, you don't want that. Read Why it's stupid to use a variable as as a variable name to get a discussion of the perils and the solutions.
You should put your data into an array instead of collecting it into numbered variables.
I'm quite confident that somebody will show you the way how to use strings as variable names, but you shouldn't use that but first think long and hard about the problem you're trying to solve, and the alternatives that Perl offers you, like hashes and arrays. If an array does not suit your needs, then a hash sure will:
my %numbers = ( num1 => 1, num2 => 2, ... num10 => 10, ); # which can be constructed programmatically as: my %numbers = map { "num$_" => $_ } (1..10);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Creating variables for each array member
by Marsel (Sexton) on Jul 25, 2006 at 09:48 UTC |