Mailing List Archive

/mo problems
There appears to be a problem with using /m and /o at the same time
in perl 5.001n when the pattern to be matched is specified by a variable.
The following program illustrates the problem:

#!/usr/local/bin/perl5 -w
#
# Program to test for /mo bug

$test_string = "This is the first line\n" .
"=======================\n" .
"This is the second line\n" .
"=======================\n" .
"This is the third line\n"
;
$PAT = "=+\n" ;

# First try with the /m switch and an non=variable pattern.

( $first, $second, $third ) = split(/=+\n/m, $test_string) ;
print "TEST 1\n" ;
print " \$first = $first" ;
print " \$second = $second" ;
print " \$third = $third" ;
print "\n" ;

# Try the same thing, but this time use a variable pattern.

( $first, $second, $third ) = split(/$PAT/m, $test_string) ;
print "TEST 2\n" ;
print " \$first = $first" ;
print " \$second = $second" ;
print " \$third = $third" ;
print "\n" ;

# Back to the explicit pattern. This time use /mo

( $first, $second, $third ) = split(/=+\n/mo, $test_string) ;
print "TEST 3\n" ;
print " \$first = $first" ;
print " \$second = $second" ;
print " \$third = $third" ;
print "\n" ;

# And now we use /mo with a variable pattern. This time we will get
# some different results.

( $first, $second, $third ) = split(/$PAT/mo, $test_string) ;
print "TEST 4\n" ;
print " \$first = $first" ;
print " \$second = $second" ;
print " \$third = $third" ;
print "\n" ;



When run, this program produces the following output:

TEST 1
$first = This is the first line
$second = This is the second line
$third = This is the third line

TEST 2
$first = This is the first line
$second = This is the second line
$third = This is the third line

TEST 3
$first = This is the first line
$second = This is the second line
$third = This is the third line

TEST 4
$first = This is the first line $second = ======================= $third = This is the second line

The first 3 tests produces the results I would expect. The last test,
however, produces some unusal results. Near as I can tell, it seems
to be treating the pattern almost as though it has parentheses around
it, except that it is also truncating the newlines from the test string.

--
Pete `-_-'

How long a minute is depends on which side of the bathroom door you're on.