From: Schuyler Erle <schuyler@oreilly.com>
Date: Fri, 01 Mar 2002 14:22:19 -0800
Message-ID: <
3C7FFF1B.
E74979B1@oreilly.com>
Subject: Re: PATCH: "splice() offset past end of array" warning.
From: Mark-Jason Dominus <mjd@plover.com>
Date: Fri, 01 Mar 2002 17:19:49 -0500
Message-ID: <
20020301221949.7610.qmail@plover.com>
p4raw-id: //depot/perl@14939
(F) A sort comparison subroutine may not return a list value with more
or less than one element. See L<perlfunc/sort>.
+=item splice() offset past end of array
+
+(W misc) You attempted to specify an offset that was past the end of
+the array passed to splice(). Splicing will instead commence at the end
+of the array, rather than past it. If this isn't what you want, try
+explicitly pre-extending the array by assigning $#array = $offset. See
+L<perlfunc/splice>.
+
=item Split loop
(P) The split was looping infinitely. (Obviously, a split shouldn't
If OFFSET is negative then it starts that far from the end of the array.
If LENGTH is omitted, removes everything from OFFSET onward.
If LENGTH is negative, leaves that many elements off the end of the array.
-If both OFFSET and LENGTH are omitted, removes everything.
+If both OFFSET and LENGTH are omitted, removes everything. If OFFSET is
+past the end of the array, perl issues a warning, and splices at the
+end of the array.
The following equivalences hold (assuming C<$[ == 0>):
offset = 0;
length = AvMAX(ary) + 1;
}
- if (offset > AvFILLp(ary) + 1)
+ if (offset > AvFILLp(ary) + 1) {
+ if (ckWARN(WARN_MISC))
+ Perl_warner(aTHX_ WARN_MISC, "splice() offset past end of array" );
offset = AvFILLp(ary) + 1;
+ }
after = AvFILLp(ary) + 1 - (offset + length);
if (after < 0) { /* not that much array */
length += after; /* offset+length now in array */
print "not " unless j(splice(@a,5,1,5)) eq "5" && j(@a) eq j(0..11);
print "ok 5\n";
-print "not " unless j(splice(@a, 20, 0, 12, 13)) eq "" && j(@a) eq j(0..13);
+print "not " unless j(splice(@a, @a, 0, 12, 13)) eq "" && j(@a) eq j(0..13);
print "ok 6\n";
print "not " unless j(splice(@a, -@a, @a, 1, 2, 3)) eq j(0..13) && j(@a) eq j(1..3);