sub compatible {
my ($s1, $s2) = @_;
$s1=~/\G_/gcs and $s2=~/./gcs or
$s1=~/./gcs and $s2=~/\G_/gcs or
return 0 until
$s1=~/\G\z/ or $s2=~/\G\z/;
1; }
print(compatible("_8__3__19", "4_8___7__") ? "true\n" : "false\n");
Update: this is wrong too, for the same reason as my other reply.
Wait, I'll try to post a correction.
Update:
Maybe this would work:
sub compatible {
my ($s1, $s2) = @_;
my $t;
$s1=~/\G_/gcs and $s2=~/./gcs or
$s1=~/(.)/gcs and $t = $1, $s2=~/\G_/gcs or $s2=~/(.)/gcs and
+$t eq $1 or
return 0 until
$s1=~/\G\z/ or $s2=~/\G\z/;
1;
}
printf "%s v %s ? %s\n", @$_, compatible( @$_ ) ? 1 : 0
for [ qw[ _8__3__19 48____7__ ] ], # compat
[ qw[ _8__3__19 4_8___7__ ] ], # compat
[ qw[ _8__3__19 48_____7_ ] ]; # clash
Update: this is wrong too.
Update:
sub compatible {
my ($s1, $s2) = @_;
my($c1, $c2, $d);
{
$s1 =~ /(.)/gs or return 1;
$c1 = $1;
$s2 =~ /(.)/gs or return 1;
$c2 = $1;
if ($c1 eq "_") {
if ($c2 eq "_")
{ }
else
{ vec($d, ord $c2, 1)++ and return; }
} else {
if ($c2 eq "_")
{ vec($d, ord $c1, 1)++ and return; }
else
{ $c1 ne $c2 and return; vec($d, ord $c2, 1)++
+ and return; }
}
redo;
}
}
printf "%s v %s ? %s\n", @$_, compatible( @$_ ) || 0
for [ qw[ _8__3__19 48____7__ ] ], # compat
[ qw[ _8__3__19 4_2___7__ ] ], # compat
[ qw[ _8__3__19 4_8___7__ ] ], # clash
[ qw[ __8_3__19 48____7__ ] ], # clash
[ qw[ __8_3__19 84____7__ ] ], # clash
[ qw[ _8__3__19 48_____7_ ] ]; # clash
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.