SimonSaysCake has asked for the wisdom of the Perl Monks concerning the following question:

I was recently working with Perl's splice function and ran into an anomaly. In this case I was testing on Windows via WAMP running ActiveState Perl ver. v5.16.3. Everything looked good but when I ran the same code on one of our Linux severs (RedHat), this one running Perl ver. v5.10.1 (yes, it's old and someday it will no longer be), I got a different result which really surprised me. Here is the code in question and the different outputs:

#!/usr/local/bin/perl use strict; use warnings; my @stuff = qw(one two three four five six seven eight nine ten); print "Before:\n\n", join(",", @stuff), "\n"; splice(@stuff, $#stuff, 0, splice(@stuff, 3, 1)); splice(@stuff, $#stuff, 0, splice(@stuff, 3, 1)); splice(@stuff, $#stuff, 0, splice(@stuff, 3, 1)); print "\nAfter:\n\n", join(",", @stuff), "\n"; exit 1;

On my Windows 10 workstation with Perl v5.16.3 I get what I expect:

Before: one,two,three,four,five,six,seven,eight,nine,ten After: one,two,three,seven,eight,nine,ten,four,five,six

But on the Linux box with Perl v5.10.1 I get something else:

Before: one,two,three,four,five,six,seven,eight,nine,ten After: one,two,three,seven,eight,nine,four,five,six,ten

Our other Linux server (Ubuntu) is running Perl ver. v5.14.2 and the test script's output on that box is the same as my Windows 10/WAMP output so it would seem to be, at least in part, a Perl version issue.

I searched here and Googled around and was surprised not find anything about this. The only reference to a change in splice's behavior that I found is regarding allowing it to accept an array ref for its EXPR argument starting with 5.14. That's considered experimental behavior and doesn't apply here since I've chosen not to use refs.

Any idea why the change in behavior? Bug? Thanks for any insight you can offer.