Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Tri state string compare?

by hdb (Monsignor)
on Dec 13, 2015 at 18:51 UTC ( [id://1150176]=note: print w/replies, xml ) Need Help??


in reply to Tri state string compare? (Solved! see update2)

Replace all "don't care characters" with . and you have a regex that does the job.

use strict; use warnings; my $abc = "AABCBAABCCCCAB"; my $ab = "AABABAABABABAB"; $abc =~ s/[^ab]/./gi; print "They match!\n" if $ab =~ /^$abc$/i;

If you want to use logical operators the following works as well

print "They match!\n" unless ($abc ^ $ab) =~ /\x{3}/;

Replies are listed 'Best First'.
Re^2: Tri state string compare?
by mr_ron (Chaplain) on Dec 14, 2015 at 16:09 UTC

    Just a variant that takes the rules of the original question a little more literally and strictly ...

    use strict; use warnings; my $abc = "AABCBAABCCCCAB"; my $ab = "AABABAABABABAB"; $abc =~ s/C/[AB]/g; $abc = qr/^$abc$/; print "They match!\n" if $ab =~ $abc;
    Ron

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (None)
    As of 2024-04-25 00:55 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      No recent polls found