Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

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.


In reply to Odd splice behavior between perl/OS versions by SimonSaysCake

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2022-11-29 02:10 GMT
Find Nodes?
    Voting Booth?