develooper Front page | perl.beginners | Postings from April 2002

Re: wipe out elements in an array

Thread Previous | Thread Next
From:
drieux
Date:
April 25, 2002 18:13
Subject:
Re: wipe out elements in an array
Message ID:
BB4ED344-58B2-11D6-85A2-0030654D3CAE@wetware.com

On Thursday, April 25, 2002, at 05:37 , Peter Scott wrote:

>
> Use splice() if you want to remove a known number of elements that are 
> all adjacent and start from a known offset.  Otherwise, use grep:
>
>         @myarray = grep { $_ != 3 && $_ != 5 } @myarray
>
> If you want to remove elements based upon some criteria applied to their 
> *index*, use an array slice.

head to head comparison grep wins:

http://www.wetware.com/drieux/CS/lang/Perl/Beginners/BenchMarks/RemoveFromArray.
txt

ciao
drieux

---


Thread Previous | 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