Clear questions and runnable code get the best and fastest answer |
|
PerlMonks |
Re: Variable Names and Referencesby Joost (Canon) |
on Mar 09, 2007 at 15:59 UTC ( [id://603998]=note: print w/replies, xml ) | Need Help?? |
${"str$_"} is not a "hard" reference, it's a symbolic reference. i.e. it just refers to the name of a variable. You can't use symbolic refences while you have "strict refs" in use (as the error correctly states).
You can use symbolic references if you switch off "strict refs": update: you can only refer to GLOBALs with symbolic references. (update2: here's the relevant documentation in perlref) That's why that code still won't work. Here's a working version:
Note that in your example using a simple array would be much easier, less error-prone and more efficient. Symbolic references are almost only useful these days for creating subroutines / packages at runtime (basically, wherever the only alternative is to use eval STRING). updated again, added some comments
In Section
Seekers of Perl Wisdom
|
|