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?
In reply to Variable Names and References by chakram88
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |