develooper Front page | perl.beginners | Postings from November 2009

splice without the remove

Thread Next
From:
Dermot
Date:
November 9, 2009 10:46
Subject:
splice without the remove
Message ID:
9c7446e70911091046r55a3e71br75cf15131dd2a315@mail.gmail.com
Hi,

I just spent 20mins scratching my head because I didn't read the docs
very closely concerning splice. I had assumed it left the array
intact, its doesn't. I was hoping for a function more akin to substr
where the return would be the offset -> length of the array but the
value it was working on remained in tact.

@array = (1, 4, 6, 9, 2);
my @list = splice(@array, 1, 3);        # @list = (1, 4, 6) and @array =(9,2)

It doesn't say but do indexes start with 0 with splice?

Is there a List::Util or similar that might meet my needs? Or do I
simple push the values back once I've used splice?
push(@array, @list);

TIA,
Dp.

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About