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

wipe out elements in an array

Thread Next
Bryan R Harris
April 25, 2002 16:59
wipe out elements in an array
Message ID:

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...


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 Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About