Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Remove elements from an array

by dimar (Curate)
on Nov 23, 2004 at 18:01 UTC ( [id://409947]=note: print w/replies, xml ) Need Help??


in reply to Remove elements from an array

Remove elements that do not match the RegEx /B.*?y/

use strict; use warnings; my @aTemp = qw(Fred Betty Barney Wilma); @aTemp = grep{$_ =~ /B.*?y/} @aTemp; print join',',@aTemp;

Remove elements that *do* match the RegEx /B.*?y/

use strict; use warnings; my @aTemp = qw(Fred Betty Barney Wilma); @aTemp = grep{$_ !~ /B.*?y/} @aTemp; print join',',@aTemp;

Note: The other examples in this thread that use 'index' are more preferable for what you asked ... but this is an alternate way in case you are curious.

Moreover, you might want to check out Categorized Questions and Answers where you can find fast answers to basic questions like How do I completely remove an element from an array ... categorized Q&A is very useful.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://409947]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (7)
As of 2024-03-28 18:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found