chakram88 has asked for the wisdom of the Perl Monks concerning the following question:
I know I'm missing something silly, but despite reading the Camel References chapter till I'm blurry, and reading the perlref tutorial I am stumped.
I understand hard references wrt using a variable name as a variable. But, if I want to create the variable name on the fly, I can't seem to get the refernce right:
outputs:#!/usr/bin/perl -l use warnings; use strict; my $str1 = qq[A-M o'Foo]; my $str2 = qq[.,rtyu_']; my $str3 = qq[$<%^]; my $str4 = qq[this works]; my $ref4 = \$str4; print $$ref4; # works as expected for (1..3) { my $ref = \${'str'.$_}; print "The string is $$ref"; }
this works Error:17: Can't use string ("str1") as a SCALAR ref while "strict ref +s" in use
I've tried multiple levels of ref/deref (i.e. \\\\$var ... $$$$$ref) but still have the same problem.
What would be the proper way to reference these variables?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Variable Names and References
by Joost (Canon) on Mar 09, 2007 at 15:59 UTC | |
by chakram88 (Pilgrim) on Mar 09, 2007 at 16:13 UTC | |
by rvosa (Curate) on Mar 12, 2007 at 00:52 UTC | |
by Joost (Canon) on Mar 12, 2007 at 10:25 UTC | |
|
Re: Variable Names and References
by dragonchild (Archbishop) on Mar 09, 2007 at 18:13 UTC | |
by Anonymous Monk on Mar 11, 2007 at 19:09 UTC | |
|
Re: Variable Names and References
by bart (Canon) on Mar 10, 2007 at 12:02 UTC | |
|
Re: Variable Names and References
by Sartan (Pilgrim) on Mar 09, 2007 at 20:25 UTC | |
by Joost (Canon) on Mar 10, 2007 at 16:19 UTC | |
|
Re: Variable Names and References
by DrHyde (Prior) on Mar 12, 2007 at 10:26 UTC | |
by Sartan (Pilgrim) on Mar 12, 2007 at 15:55 UTC |