Front page | perl.beginners |
Postings from April 2003
Re: multiple sorts
Thread Previous
|
Thread Next
From:
John W. Krahn
Date:
April 30, 2003 15:07
Subject:
Re: multiple sorts
Message ID:
3EB04939.CE0A73EC@acm.org
Kevin Pfeiffer wrote:
>
> my @array = qw(
> apple
> pear
> orange
> peach
> grape
> );
>
> my @temp = splice @array, 0, 2;
>
> print "Here is \@temp: @temp\n";
> print "Here is \@array: @array\n";
>
> # didn't work - LENGTH 0 removes everything!
> #@array = splice @array, 0, 0, @temp;
The problem is that you are assigning the return value of splice to the
array you are modifying. splice modifies the array in place and return
the elements that were REMOVED (you are not removing anything) so it
should be:
splice @array, 0, 0, @temp;
John
--
use Perl;
program
fulfillment
Thread Previous
|
Thread Next