Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re^3: Reg exps?

by fod (Friar)
on Jan 14, 2010 at 18:48 UTC ( #817458=note: print w/replies, xml ) Need Help??


in reply to Re^2: Reg exps?
in thread Reg exps?

This is more or less redundant after toastbread's response and quite possibly naive but I've done it now and it seems to do what the OP wanted:
use strict; use warnings; my $my_name="Acidovorax JS42"; my $db_name="Acidovorax sp. JS42"; my @names = split " ", $my_name; my $numel = @names; #number of words to match my $count; foreach (@names) { if ($db_name=~/^|\s\Q$_\E$|\s/) { $count++; #count matches } } print "MATCH" if $count==$numel; #report match if all words match
--->Updated to fix regex - thx JavaFan

Replies are listed 'Best First'.
Re^4: Reg exps?
by JavaFan (Canon) on Jan 14, 2010 at 19:06 UTC
    You would have to escape $_ as it may contain regexp special characters. It also assumes "words" are delimited by whitespace and by \b at the same time - your program fails to find a match if $my_name=$db_name="Acidovorax sp. JS42" for instance.
      Ouch! I guess I should learn to program before I start (mis)representing myself as someone who knows what he's talking about. I've updated the post with what I think might possibly work. Thanks for the heads up.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://817458]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (3)
As of 2018-02-25 04:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    When it is dark outside I am happiest to see ...














    Results (312 votes). Check out past polls.

    Notices?