What is the equivalent of grep -v
in Perl?
The code looks like this
@files = reversegrep(/^[ ]+$/, @files);
I want @files
to have a list of all the file names that are not empty.
The Perl grep() function is a filter that runs a regular expression on each element of an array and returns only the elements that evaluate as true. Using regular expressions can be extremely powerful and complex. The grep() functions uses the syntax @List = grep(Expression, @array).
You can use negation in the expression or block:
@files = grep !/^\s+$/, @files;
See perldoc grep.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With