Problems? Is your data what you think it is? | |
PerlMonks |
Re^3: Why Perl gets confused here?by LanX (Saint) |
on Oct 27, 2017 at 14:18 UTC ( [id://1202151]=note: print w/replies, xml ) | Need Help?? |
Context matters. This is list context (( substr( $q, 0, 1 )) = '123' ) = 'x'; But the OP happened in scalar context, see Ikegami's footnote. "substr evaluates its first operand in scalar context." > More confusing is "xbc" -- I'd expect $q to be "123bc", and "x" to be gone into fathomless void, as in OP? Depending on your Perl version you can assign multiple times to the same lvalue. in this case first 123 then x See substr documentation Note that the lvalue returned by the three-argument version of substr acts as a 'magic bullet'; each time it is assigned to, it remembers which part of the original string is being modified To avoid confusion, I'd suggest using the 4 parametric version instead of the lvalue variant.
Cheers Rolf
In Section
Seekers of Perl Wisdom
|
|