Front page | perl.perl5.porters |
Postings from April 2003
Re: slice autoextending ?
Thread Previous
|
Thread Next
From:
david nicol
Date:
April 22, 2003 17:26
Subject:
Re: slice autoextending ?
Message ID:
1051057502.1446.46.camel@plaza.davidnicol.com
Splice is about removing, then replacing. When you are removing
the eleventh item from an empty array, well you're not going
to get anything back from it.
Splice logic is really confusing, so we DO NOT want to change
any behavior of any code.
The piece of the docs that leads to the expectation of autoextension
is the last line of
The following equivalences hold (assuming "$[ ==
0"):
push(@a,$x,$y) splice(@a,@a,0,$x,$y)
pop(@a) splice(@a,-1)
shift(@a) splice(@a,0,1)
unshift(@a,$x,$y) splice(@a,0,0,$x,$y)
$a[$x] = $y splice(@a,$x,1,$y)
I think the tightest way to fix this would be to extend
the caveat:
The following equivalences hold (assuming "$#a >= $x"
and "$[ == 0" ):
On Tue, 2003-04-22 at 17:35, Dave Mitchell wrote:
> bugid #1832 points out that there is an inconsistency between the docs and
> the behaviour of splice, in that the array isn't autoextended if
> the offset is off the end; eg
>
> perl -le 'splice(@x,10,1,'foo'); print 0+@x'
>
> prints 1 rather than 10.
>
> The bug dialogue contains proposals both for a doc patch or a code patch,
> but no concensus was reached (or even attempted, it would appear) as to
> which it should be.
>
> I would vote for fixing the docs.
> Any dissenters?
--
David Nicol, independent consultant and contractor
have a nice day, really. http://www.funnytimes.com
Thread Previous
|
Thread Next