Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hello monks! My question has to do with patttern matching and parentheses. In particular, I have 2 files, like the following:
FILE1 jim( 4 john 5 mark 9

FILE2 jim( 4 john 5 mark 9

What I want to do is loop through FILE1, store names and numbers and then loop through FILE2 and, if I find the same name, print its number also. I have no problem with john and mark, but, when it comes to jim, I can't get Perl to match it because of the (
Note that if I had (jim) in both cases, it would be ok.
Thank you in advance

Replies are listed 'Best First'.
Re: match ( ?
by FunkyMonk (Bishop) on Mar 31, 2008 at 18:12 UTC
    you need to quote it either using \Q ... \E or quotemeta:
    my $jim = "jim("; my $string = "A string with jim( in it"; print "yeah" if $string =~ m/\Q$jim\E/; #or $jim = quotemeta $jim; print "yeah" if $string =~ m/$jim/;

Re: match ( ?
by Fletch (Bishop) on Mar 31, 2008 at 18:18 UTC

    Alternately to quotemeta, use index instead of a regex to match plain strings without involving regexen.

    The cake is a lie.
    The cake is a lie.
    The cake is a lie.

Re: match ( ?
by runrig (Abbot) on Mar 31, 2008 at 18:17 UTC
    Show us some code (what have you tried?), and then maybe we can help you with your homework.