Beefy Boxes and Bandwidth Generously Provided by pair Networks
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??


in reply to Re^2: Why Perl gets confused here?
in thread Why Perl gets confused here?

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
(addicted to the Perl Programming Language and ☆☆☆☆ :)
Je suis Charlie!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1202151]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (3)
As of 2024-04-26 06:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found