Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Odd splice behavior between perl/OS versions (undefined)

by tye (Sage)
on Oct 28, 2016 at 19:14 UTC ( [id://1174913]=note: print w/replies, xml ) Need Help??


in reply to Odd splice behavior between perl/OS versions

The behavior depends on the order in which different parts of the operation are done. If this were C code, then it would be labeled "undefined behavior". Since it is Perl code, the strict meaning of that phrase from the C standard doesn't quite apply. But it is the type of behavior that is the most likely to end up changing when mundane maintenance is done on Perl's source code, including optimizations.

I believe the crux of the difference is whether you get the value of $#stuff passed to the outer instance of splice from before or after the inner instance of splice has removed $stuff[3]. Though I can also imagine more complex ways that a simple optimization, bug fix, or just reworking of Perl's code could cause your code to behave differently.

Avoid changing @stuff in multiple ways in a single expression and using values like $#stuff from within an expression where that value is changed.

- tye        

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (4)
As of 2024-04-23 22:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found