http://www.perlmonks.org?node_id=1018620

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I have a question on a problem that occured in v5.12.4 using Ubuntu:

My code makes it neccessary to loop through an array and to output all elements using a reference. My first try did not work as expected (simplyfied example):

$sref = \$string; foreach $string ( @array_of_strings ) { print $$sref; }
However, the following code does work (and is my solution):
$sref \$string1; foreach $string2 ( @array_of_strings ) { $string1 = $string2; print $$sref; }
Why? I would have expected that using the foreach $string acutally is assigned to whatever is the element of the array but aparently this is not the case. In the first example the print will only print what was assigned to $string before executing the foreach loop. Of course my actual code isn't that simple.