Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: how to add more intelligence to grep functionality

by blazar (Canon)
on Jan 12, 2006 at 11:28 UTC ( [id://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.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (7)
As of 2024-04-23 12:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found