Front page | perl.perl5.porters |
Postings from April 2000
[ID 20000420.007] weird matching in while //g
Thread Next
From:
Cristi
Date:
April 20, 2000 23:35
Subject:
[ID 20000420.007] weird matching in while //g
Message ID:
200004210634.CAA03885@salvages.obs-us.com
This is a bug report for perl from cristi@obs-us.com,
generated with the help of perlbug 1.26 running under perl 5.00502.
-----------------------------------------------------------------
[Please enter your report here]
Hello perl porters,
I am trying to match in a string (file buffer) and as I like to write
code in as little characters as possible I had the matching expression
in one line like:
function while match;
But I wasn't getting the right result so I tryed couple of different tests
till I realized what happens. I enclosed a little example program that
shows what I might stumbled upon. I don't know if this is realy a bug, but I
consider it so since I didn't find any explanation in the man page about
a possible feature or limitation. Anyhow I didn't search thorougly as I went
many times over the man page and books and I would've remembered such thing.
cheers,
cristi
P.S. Same thing on 5.6.0 on WinNT
#!/usr/local/bin/perl5
$a = "AA\r\nBB";
$b = "A\r\n";
$da = $a;
$db = $b;
$da =~ s/\r/\\r/g; $da =~ s/\n/\\n/g;
$db =~ s/\r/\\r/g; $db =~ s/\n/\\n/g;
print "a: $da\n";
print "b: $db\n";
print "OK match follows\n";
while ( $a =~ /$b/g )
{
$p = $`;
$m = $&;
$n = $';
$p =~ s/\r/\\r/g; $p =~ s/\n/\\n/g;
$m =~ s/\r/\\r/g; $m =~ s/\n/\\n/g;
$n =~ s/\r/\\r/g; $n =~ s/\n/\\n/g;
print "MATCH p:$p\n";
print "MATCH m:$m\n";
print "MATCH n:$n\n";
}
print "WRONG match follows\n";
do {
$p = $`;
$m = $&;
$n = $';
$p =~ s/\r/\\r/g; $p =~ s/\n/\\n/g;
$m =~ s/\r/\\r/g; $m =~ s/\n/\\n/g;
$n =~ s/\r/\\r/g; $n =~ s/\n/\\n/g;
print "MATCH p:$p\n";
print "MATCH m:$m\n";
print "MATCH n:$n\n";
}
while $a =~ /$b/g;
1;
Produces:
a: AA\r\nBB
b: A\r\n
OK matching follows
MATCH p:A
MATCH m:A\r\n
MATCH n:BB
WRONG matching follows
MATCH p:A\r
MATCH m:\n
MATCH n:
MATCH p:A
MATCH m:A\r\n
MATCH n:BB
[Please do not change anything below this line]
-----------------------------------------------------------------
---
Site configuration information for perl 5.00502:
Configured by storm at Mon Mar 8 16:58:30 EST 1999.
Summary of my perl5 (5.0 patchlevel 5 subversion 2) configuration:
Platform:
osname=solaris, osvers=2.7, archname=sun4-solaris-thread
uname='sunos salvages 5.7 generic sun4u sparc sunw,ultra-5_10 '
hint=recommended, useposix=true, d_sigaction=define
usethreads=define useperlio=undef d_sfio=undef
Compiler:
cc='cc', optimize='-O', gccversion=2.8.1
cppflags='-D_REENTRANT -I/usr/local/include'
ccflags ='-D_REENTRANT -I/usr/local/include'
stdchar='char', d_stdstdio=define, usevfork=false
intsize=4, longsize=4, ptrsize=4, doublesize=8
d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16
alignbytes=8, usemymalloc=y, prototype=define
Linker and Libraries:
ld='cc', ldflags =' -L/usr/local/lib'
libpth=/usr/local/lib /lib /usr/lib /usr/ccs/lib
libs=-lsocket -lnsl -ldl -lm -lposix4 -lpthread -lc -lcrypt
libc=/lib/libc.so, so=so, useshrplib=false, libperl=libperl.a
Dynamic Linking:
dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags=' '
cccdlflags='-fPIC', lddlflags='-G -L/usr/local/lib'
Locally applied patches:
---
@INC for perl 5.00502:
/usr/local/lib/perl5/5.00502/sun4-solaris-thread
/usr/local/lib/perl5/5.00502
/usr/local/lib/perl5/site_perl/5.005/sun4-solaris-thread
/usr/local/lib/perl5/site_perl/5.005
.
---
Environment for perl 5.00502:
HOME=/export/home/systems/tech/cristi
LANG (unset)
LD_LIBRARY_PATH (unset)
LOGDIR (unset)
PATH=/usr/ucb:/usr/gnu/bin:/bin:/usr/bin:/usr/ucb:/usr/bin/X11:/usr/local/bin:/usr/local/bin:/usr/local/bin:/usr/sbin:/usr/bin:/usr/local/bin:/bin:/usr/xpg4/bin:/opt/RICHPse/examples:/usr/ccs/bin:/usr/openwin/bin:.
PERL_BADLANG (unset)
SHELL=/usr/local/bin/bash
Thread Next
-
[ID 20000420.007] weird matching in while //g
by Cristi