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

wipe out elements in an array

Thread Next
From:
Bryan R Harris
Date:
April 25, 2002 16:59
Subject:
wipe out elements in an array
Message ID:
OF64421FAB.2B686C42-ON07256BA6.0083527B@rsc.raytheon.com

I have another question that Learning Perl doesn't seem to address:

I'd like to remove all elements in an array that meet a certain criteria
without changing their order.  I'm sure this gets done all the time, but
I'm not sure how to do it...

Help?

My guess (this is just an example):

@myarray = (1,2,3,4,5,6,7,8,9,10);
foreach (@myarray) { if ($_ == 3 || $_ == 5) { undef($_); } }

But I don't think it's working right...

- B


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