Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

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?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://817458]
[usemodperl]: just because of banking apps on free wifi, and porn, i guess...
usemodperl thinks every1 should serve HTTP on port 80 incase we don't care about encryption, right? wtf

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (5)
As of 2018-06-24 09:31 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (126 votes). Check out past polls.