[Israel.pm] How to remove elements according to a filter from an array

Gaal Yahas gaal at forum2.org
Fri May 25 01:10:04 EEST 2007


delete for arrays has been there for a while now--at least since5.002, and I think earlier too. Note that deleting an element doesn'tmodify other elements' indexes, so if you delete stuff from the middleyou get undefined cells instead. If you need to shift up stuff you canuse split, but that's slow!
On 5/24/07, Yossi Itzkovich <Yossi.Itzkovich at ecitele.com> wrote:>>  Thanks, the man page seems promising.  But I was surprised to see that delete (and exists) work for arrays, I always thought they were there for hashes only. Is it something new, or just my ignorance ?>> Yossi>> -----Original Message-----> From: perl-bounces at perl.org.il [mailto:perl-bounces at perl.org.il] On Behalf Of yaron at kahanovitch.com> Sent: Thursday, May 24, 2007 10:54 PM> To: Perl in Israel> Cc: Perl in Israel> Subject: Re: [Israel.pm] How to remove elements according to a filter from an array>> Hi>> See perldoc -f delete.>> 4 example (Untested)>> foreach $index (0 .. $#ARRAY) {>         delete $ARRAY[$index] if (criteria);>     }>>> YAron Kahanovitch> ----- Original Message -----> From: "Yossi Itzkovich" <Yossi.Itzkovich at ecitele.com>> To: "Perl in Israel" <perl at perl.org.il>> Sent: 20:36:29 (GMT+0200) Africa/Harare יום חמישי 24 מאי 2007> Subject: [Israel.pm] How to remove elements according to a filter from an array>> Hi,>> Assuming I have a big array, and I want to remove elemnts according to a> criteria, how do I do it ?> Please note, I am not asking about getting a new list of elements that> passed the filter (like grep does), but removing the items from the> original list.  For a big array (and assuming that arrays are> implemented with linked list (is it ?)), then removing items from the> original list might be much faster.>>> Yossi>> _______________________________________________> Perl mailing list> Perl at perl.org.il> http://perl.org.il/mailman/listinfo/perl>>> _______________________________________________> Perl mailing list> Perl at perl.org.il> http://perl.org.il/mailman/listinfo/perl>> _______________________________________________> Perl mailing list> Perl at perl.org.il> http://perl.org.il/mailman/listinfo/perl>

-- Gaal Yahas <gaal at forum2.org>http://gaal.livejournal.com/



More information about the Perl mailing list