* Mark Fowler <[EMAIL PROTECTED]> [2002-07-18 12:39]:
> I don't see why the case where you're replacing should be the only one
> that's destructive here. For example, even two argument splice in perl is
> destructive:
????
> @foo = (1,2,3,4,5);
> @bar = splice(@foo,2);
> print Dumper \@foo;
> print Dumper \@bar;
> $VAR1 = [
> 1,
> 2
> ];
> $VAR1 = [
> 3,
> 4,
> 5
> ];
*smacks forhead*
It never actually dawned on my that all splices are destructive. Of
course I knew that, and have relied on it in tons of places:
while (@array) {
my ($this, $that) = splce @array, 0, 2;
...
But I didn't make the connection here.
> I don't like the difference in the two ways splice operates.
Yes, I agree. New suggested sub below.
> Does this all make sense or have I totally lost the plot?
Nope, it was I who was confused. Ok, so *now* how does this look:
sub list_splice_vmeth {
my ($list, $offset, $length, @replace) = @_;
if (@replace) {
splice @$list, $offset, $length, @replace;
}
elsif (defined $length) {
splice @$list, $offset, $length;
}
elsif (defined $offset) {
splice @$list, $offset;
}
return "";
}
All my tests pass.
(darren)
--
Lackland's Laws:
(1) Never be first.
(2) Never be last.
(3) Never volunteer for anything