Clear questions and runnable code get the best and fastest answer |
|
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
You don't need to be an utter cowdawg towards the OP -- strict and warnings are irrelevant to his issue. I don't fully grok the semantics of foreach but I suspect the correct answer is as follows: $sref = \$string sets $sref to point to the variable $string. All is well here. But then foreach enters the picture and localises $string -- this $string is only available to the inner loop. $sref continues pointing to the $string in the outer loop. Testing this without the string reference:
Yep, looks like what I described. Now, if you add the $sref, you'll notice it'll print the outer loop value for the whole time -- it points to the wrong $string. In reply to Re^2: Dereference string in foreach
by Anonymous Monk
|
|