http://www.perlmonks.org?node_id=1003957


in reply to Re^2: How to grep exact string
in thread How to grep exact string

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

Replies are listed 'Best First'.
Re^4: How to grep exact string
by tobyink (Canon) on Nov 15, 2012 at 08:38 UTC

    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'
      Ah yes! Good point. Thanks.

      EDIT: But wait.... Your suggestion of grep { $_ eq $unique } @first_list_new isn't detecting any actual matches for me.

      EDIT #2: Nevermind... tyop. er, typo.

        It's not clear why this would be. grep {$_ eq $unique} should be exactly equivalent to grep /^$unique$/, as long as $unique doesn't have any regex metacharacters--and it doesn't appear to in the sample data.


        When's the last time you used duct tape on a duct? --Larry Wall