pattern matching dynamic strings w/ regex ending in $ problem

R

rader

I'm seeing a simple, ah, problem with perl 5.8.0...

chive(rader): perl -v | head -2 | tail -1
This is perl, v5.8.0 built for i386-linux-thread-multi

chive(rader): cat crud
#!/usr/bin/perl
$a = 'fuBar';
$b = 'Bar$';
$a_new = `echo -n $a`;
$b_new = `echo -n $b`;
if ( $a_new =~ /$b_new/ ) {
print "match\n";
} else {
print "no match?!\n";
}

chive(rader): ./crud
no match?!

Anybody know of a workaround? The code above behaves as expected
with 5.6.x. Could this actually be a bug?

steve
- - -
systems & network manager
high energy physics
university of wisconsin
 
C

Christopher Nehren

On 2005-05-02, rader scribbled these
curious markings:

[Posting to both clpmod and clpmisc is largely superfluous. Following up
to and F'ups set to clpmisc.]
chive(rader): cat crud
#!/usr/bin/perl
$a = 'fuBar';
$b = 'Bar$';
$a_new = `echo -n $a`;
$b_new = `echo -n $b`;
if ( $a_new =~ /$b_new/ ) {
print "match\n";
} else {
print "no match?!\n";
}

chive(rader): ./crud
no match?!

Make sure that the results of the echo commands are actually what you
expect. FWIW, it WFM on 5.8.6 i386-freebsd-thread-multi-64int.

Best Regards,
Christopher Nehren
 
P

Paul Arthur

rader said:
I'm seeing a simple, ah, problem with perl 5.8.0...

chive(rader): perl -v | head -2 | tail -1
This is perl, v5.8.0 built for i386-linux-thread-multi

[paul@linux ~]$ perl -v

This is perl, v5.8.5 built for i386-linux-thread-multi

[paul@linux ~]$ cat rader.pl
#!/usr/bin/perl

use strict;
use warnings;

my $a = 'fuBar';
my $b = 'Bar$';
my $a_new = `echo -n $a`;
my $b_new = `echo -n $b`;
if ( $a_new =~ /$b_new/ ) {
print "match\n";
} else {
print "no match?!\n";
}
chive(rader): ./crud
no match?!

[paul@linux ~]$ ./crud.pl
match
Anybody know of a workaround? The code above behaves as expected
with 5.6.x. Could this actually be a bug?

If it is a bug, it's been fixed.
 
E

Ed

If it is a bug, it's been fixed.

(Paul had used 5.8.5, where the problem did not appear.)

I did some further poking at the problem with 5.8.0 (below). From what
I see there, there may still be a bug with 5.8.5. I'm not that familiar
with perl's UTF-8 handling, so bear with me if I misstate something
here... The regex debug information indicates that UTF-8 came into play
(for the problem case). I believe UTF-8 was enabled by default for
5.8.0 and backed out with 5.8.1. So 5.8.5 may have the bug, but it
could be masked since UTF-8 isn't enabled.

Ed


$ cat crud
#!/usr/local/bin/perl
use strict;
use warnings;

use re 'debug';

my $a = 'fuBar'; my $a_new = qx(echo -n $a);
my $b = 'Bar$';

if ( $a eq $a_new ) {
print "===> \$a eq \$a_new is true\n";
}

print "===> (\$a vs. \$b ) $a =~ /$b/ ...\n";
if ( $a =~ /$b/ ) {
print "===> match\n";
} else {
print "===> no match?!\n";
}

print "===> (\$a_new vs. \$b ) $a_new =~ /$b/ ...\n";
if ( $a_new =~ /$b/ ) {
print "===> match\n";
} else {
print "===> no match?!\n";
}

print "===> (\$a_new vs. Bar\$) $a_new =~ /Bar\$/ ...\n";
if ( $a_new =~ /Bar$/ ) {
print "===> match\n";
} else {
print "===> no match?!\n";
}
$ ./crud
Compiling REx `Bar$'
size 4 Got 36 bytes for offset annotations.
first at 1
rarest char B at 0
1: EXACT <Bar>(3)
3: EOL(4)
4: END(0)
anchored `Bar'$ at 0 (checking anchored isall) minlen 3
Offsets: [4]
1[3] 0[0] 4[1] 5[0]
Omitting $` $& $' support.

EXECUTING...

===> $a eq $a_new is true
===> ($a vs. $b ) fuBar =~ /Bar$/ ...
Compiling REx `Bar$'
size 4 Got 36 bytes for offset annotations.
first at 1
rarest char B at 0
1: EXACT <Bar>(3)
3: EOL(4)
4: END(0)
anchored `Bar'$ at 0 (checking anchored isall) minlen 3
Offsets: [4]
1[3] 0[0] 4[1] 5[0]
Guessing start of match, REx `Bar$' against `fuBar'...
Found anchored substr `Bar'$ at offset 2...
Starting position does not contradict /^/m...
Guessed: match at offset 2
===> match
===> ($a_new vs. $b ) fuBar =~ /Bar$/ ...
Compiling REx `Bar$'
size 4 Got 36 bytes for offset annotations.
first at 1
rarest char B at 0
1: EXACT <Bar>(3)
3: EOL(4)
4: END(0)
anchored utf8 `Bar'$ at 0 (checking anchored isall) minlen 3
Offsets: [4]
1[3] 0[0] 4[1] 5[0]
UTF-8 regex...
UTF-8 target...
Guessing start of match, REx `Bar$' against `fuBar'...
Did not find anchored substr `Bar'$...
Match rejected by optimizer
===> no match?!
===> ($a_new vs. Bar$) fuBar =~ /Bar$/ ...
Matching REx `Bar$' against `fuBar'
Setting an EVAL scope, savestack=9
2 <fu> <Bar> | 1: EXACT <Bar>
5 <fuBar> <> | 3: EOL
5 <fuBar> <> | 4: END
Match successful!
===> match
Freeing REx: `"Bar$"'
Freeing REx: `Bar$'
Freeing REx: `"Bar$"'
$
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top