Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: How to grep exact string

by tobyink (Abbot)
on Nov 15, 2012 at 07:18 UTC ( #1003946=note: print w/ replies, xml ) Need Help??


in reply to How to grep exact string

if (grep { $_ eq $unique } @first_list_new) { ...; }
perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'


Comment on Re: How to grep exact string
Download Code
Re^2: How to grep exact string
by Divakar (Sexton) on Nov 15, 2012 at 08:04 UTC
    Hi tobyink, did you try this? i am getting syntax error if i replaced with what you gave. Thanks & Regards, Divakar
      I believe the way you have it is a correct way to do it (see grep):
      grep ( /^$unique$/, @first_list_new )
      An alternate syntax is:
      grep { /^$unique$/ } @first_list_new

        That's not a search for an exact string though. $unique might contain regexp metacharacters like ".".

        perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'

      My suggested grep has been correct Perl syntax since Perl 5.0. (Perhaps before?)

      Note there are no parentheses after the grep... not this:

      grep({ ... } @list)

      And note that there's no comma after the block... not this:

      grep { ... }, @list

      It just needs to be like this:

      grep { ... } @list

      If you really want parentheses, they can go on the outside:

      (grep { ... } @list)
      perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'
        I think what is breaking it for me is the $_ eq $unique. When I include that, real matches don't register as matches.

        EDIT: nevermind... typo.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (6)
As of 2015-07-05 03:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (60 votes), past polls