in reply to Dereference string in foreach
In the second snippet, you are using $string1 which is not localized. Therefore, $ref really points to it, and since you assign the value from the loop variable to it, you can acces the value by the reference. Note, though, that this is only a copy of the original value, which means you cannot change the original @array_of_strings by changing $$ref or $string1, but only $string2.$sref = \$string; foreach $string ( @array_of_strings ) { print $sref, \$string, "\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Dereference string in foreach
by 7stud (Deacon) on Feb 13, 2013 at 23:01 UTC |