qr// doesn't handle m modifier?

A

adam

The following program doesn't do what I expected. The second and third
"print" statements print, but the first one doesn't. It looks as
though when the match operator uses a regular expression constructed
with qr//, the "m" modified that should have been stored in the regular
expression is ignored. Did I do something wrong, or is this a bug in
Perl? perl -v says 5.005_03.

-- thanks, Adam


$pat = "a\$";
$re = qr/$pat/m;
$s = "a\nb";
print "Matches with qr\n" if $s =~ /$re/;
print "Matches without qr\n" if $s =~ /$pat/m;
print "Matches with qr and m flag\n" if $s =~ /$re/m;
 
X

xhoster

I get the same behavior as you do, using 5.8.8.
(?imsx-imsx) => check perldoc perlre

I don't think his question is where the behavior is described, but
rather why the actual behavior does not seem to match the description that
perlre gives.

I'm rather stumped on that, too.

Xho
 
X

xhoster

Strange. I see the problem with 5.6.1 but not with 5.8.8 (nor with
bleadperl 5.9.4).

Just to make sure we aren't miscommunicating, I get this:

$ perl -le '$pat="a\$"; $re=qr/$pat/m; my $s="a\nb"; \
print $re; print $s=~/$re/?"good":"bad" '
(?m-xis:a$)
bad

This is perl, v5.8.8 built for i686-linux-thread-multi
This is perl, v5.8.0 built for i386-linux-thread-multi
This is perl, v5.8.7 built for x86_64-linux
This is perl, v5.8.3 built for x86_64-linux-thread-multi

(If I replace the $re with the literal string "(?m-xis:a$)", I get
"good" in all situations.

Xho
 
A

anno4000

Just to make sure we aren't miscommunicating, I get this:

$ perl -le '$pat="a\$"; $re=qr/$pat/m; my $s="a\nb"; \
print $re; print $s=~/$re/?"good":"bad" '
(?m-xis:a$)
bad

This is perl, v5.8.8 built for i686-linux-thread-multi
This is perl, v5.8.0 built for i386-linux-thread-multi
This is perl, v5.8.7 built for x86_64-linux
This is perl, v5.8.3 built for x86_64-linux-thread-multi

(If I replace the $re with the literal string "(?m-xis:a$)", I get
"good" in all situations.

I'm seeing mixed results. The two good ones are both on the same
machine. I have no idea what's going on.

(?m-xis:a$)
bad

This is perl, v5.9.4 built for i686-linux
This is perl, v5.9.4 DEVEL28362 built for i386-freebsd-thread-multi
This is perl, v5.8.7 built for i586-linux
This is perl, v5.8.5 built for i686-linux
This is perl, v5.6.2 built for i386-freebsd

(?m-xis:a$)
good

This is perl, v5.8.8 built for i686-linux
This is perl, v5.9.4 DEVEL28658 built for i686-linux

Anno
 

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,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top