lightoverhead has asked for the wisdom of the Perl Monks concerning the following question:
monks,
I have a question regarding substr function. below is thr example from perldoc:
$x = '1234'; for (substr($x,1,2)) { $_ = 'a'; print $x,"\n"; # prints 1a4 $_ = 'xyz'; print $x,"\n"; # prints 1xyz4 $x = '56789'; $_ = 'pq'; print $x,"\n"; # prints 5pq9 }
I cannot get it why the last result is "5pq9" instead of "5pq89".Apparently,it's related to the claim "each time it is assigned to, it remembers which part of the original string is being modified". but i just don't know how is this rule applied to this case. thank you.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: substr question
by Loops (Curate) on Aug 03, 2013 at 18:31 UTC | |
by johngg (Canon) on Aug 04, 2013 at 13:05 UTC | |
by lightoverhead (Pilgrim) on Aug 05, 2013 at 23:07 UTC | |
by lightoverhead (Pilgrim) on Aug 05, 2013 at 23:05 UTC |