in reply to Dynamic variables
It hasn't yet been said in this thread, and should have been: Don't try to do what you're trying to do.
The advice to use a hash is the obligatory right answer under most situations where you might be tempted to create variable names on the fly, at runtime.
What you're trying to do, in your specific case, is create a symbolic reference, or a soft reference. A symbolic (or soft) reference, in Perl, is where you use some value (computed or stored in a variable) to indicate the name of a variable. Perl lets you do this (if you use the right syntax, and if you don't use strict;). Don't be tempted to use this "feature" of Perl, until you're intimately familiar with the reasons why you shouldn't use this feature.
Almost always, it's better to use a hash, or hard references, or some combination of the two. The fact is that the package global namespace really is just a glorified hash anyway. If that's good enough for perl (the executable), it's probably good enough for you too... but don't muck around with your program's package global namespace hash (Ugh, what a mess that would be!)... use your own hash to hold these dynamic names. Treating your package global namespace like a symbolic scratchpad is sooner or later (probably sooner) cause you a lot of headaches in the form of hard-to-find bugs, latent bugs, variable collisions, and so on. As merlyn once said, "If you're just here to watch the play, stay out from behind the curtain." (that's from memory, so it may be a little less than a direct quote)
Dave
|
|---|