Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

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

or

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.


Comment on Re: how to add more intelligence to grep functionality
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (7)
As of 2014-09-20 09:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (158 votes), past polls