Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

Re: how to add more intelligence to grep functionality

by blazar (Canon)
on Jan 12, 2006 at 11:28 UTC ( #522675=note: print w/replies, xml ) Need Help??

in reply to how to add more intelligence to grep functionality

You already received a lot of replies. The common consensus seems to be that you just mistook shell patterns for regular expressions. It seems to me that no one has stressed enough that you seem to have a poor understanding of grep: it is made for grepping across lists, and indeed you can pass it a list of exactly one element - only, you generally just don't want to! So you either want:

my @matching elements=grep /$wahtever/, @array; print $_, "\n" for @matching elements; # But then just: # print $_, "\n" for grep /$wahtever/, @array; # if you don't need @matching elements elsewhere


foreach (@array) { print "Matched :$_:\n" if /$value/; }

or even

/$value/ and print "Matched :$_:\n" for @array;

But then I have the feeling that you really wanted to ask about something different, since in all earnestness I couldn't make 100% sense of your wording.

Incidentally, to define that long list of "words", you may use use qw// to great advantage, improving readability, typing speed and possibly reducing the risk of typos.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://522675]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2018-05-23 18:57 GMT
Find Nodes?
    Voting Booth?