"splice () offset past end of array" in different versions of Perl

17

Today, in my work, I wrote something like that, in Perl:

my @x = qw( 1 2 3 4 5 );
splice(@x, 10);

and the error occurred:

  

splice () offset past end of array at ./x line X.

But on my personal laptop, there is no error like that. I already know that it's easy to delete the message (in English) with no warnings 'misc'; , but my question is:

Why is the difference between Perl versions?

At work, I see the message with Perl 5.14, and on my personal computer I do not see it with Perl 5.20. When did you change it, and why?

    
asked by Flimzy 30.10.2015 в 16:37
source

2 answers

9

As I mentioned, I do not use Perl, but looking at the documentation in a part of it says the following:

  

"If the displacement is beyond the end of the matrix, Perl issues   a warning, and (Perl) splices / splice at the end of the array. "

... If OFFSET is past the end of the array, Perl issues a warning, and splices at the end of the array.

In fact I have reviewed in several versions and it is the same at least the documentation warns about the warning .

Here are the links (in English);

According to the previous thing the normal thing is the warning , but reason why it is possible to be seen in the following link, not in all the versions is thus and also depends on the OS.

link

I think that happens between the 5.14 and 5.16 in some systems, here you can see the bug notification but maybe it also happens to you in the 5.20 due to your OS and it is not that something has changed .

link

    
answered by 31.10.2015 / 02:15
source
7

I will join with the part of the question that has not been answered yet: Why did it change?

Change why the intention of this code:

my @x = qw( 1 2 3 4 5 );
splice(@x, 3);

It is clearly truncate the array if it is too long and there is no reason to issue a warning if the array has less elements than the maximum specified (as in the case quoted in the question)

Source (in English)

    
answered by 31.10.2015 в 03:54