On 11/9/09 Mon Nov 9, 2009 10:46 AM, "Dermot" <paik...@googlemail.com> scribbled:
> 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? Yes, unless you have changed the value of $[, but don't do that! > > 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); If you want a subset of a list without modifying the original list, use a "list slice": my @list = @array[1..3]; See 'perldoc perldata' and search for 'Slices'. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/