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.
In reply to Re: Remove elements from an array
by dimar
in thread Remove elements from an array
by rementis
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |