Front page | perl.perl5.porters |
Postings from October 2003
[perl #24176] inconsistent m/.../g behaviour
Thread Next
From:
Jonathan Eisler
Date:
October 10, 2003 23:45
Subject:
[perl #24176] inconsistent m/.../g behaviour
Message ID:
rt-24176-65880.16.6098539669015@rt.perl.org
# New Ticket Created by Jonathan Eisler
# Please include the string: [perl #24176]
# in the subject line of all future correspondence about this issue.
# <URL: http://rt.perl.org/rt2/Ticket/Display.html?id=24176 >
This is a bug report for perl from johny@rift.com,
generated with the help of perlbug 1.26 running under perl 5.00503.
-----------------------------------------------------------------
[Please enter your report here]
I think this is a bug, but it may just be strange behaviour: global
matching (ie: m/.../g ) behaves differently when the extracted results are
saved to lexical variables or when the $1, $2, etc, implicit variables are
used.
Consider:
my $text = "Foo\nBar\n";
while ( $text =~ /(\w+)/g ) { print $1, "\n" }
The above script prints 2 lines to standard out, as expected:
"Foo\nBar\n".
Now consider:
my $text = "Foo\nBar\n";
while ( my ( $name ) = ( $text =~ /(\w+)/g ) ) { print $name, "\n" }
The above script goes into an infinite loop, printing "Foo\n" to stdout
over and over.
Shouldn't the two scripts behave equivalently?
Note, I've tested this on:
perl 5.00503 for freebsd
perl 5.8.1 for linux
perl 5.8.0 for darwin
I get the same behaviour on all 3.
[Please do not change anything below this line]
-----------------------------------------------------------------
---
Site configuration information for perl 5.00503:
Configured by markm at Sun Mar 5 13:39:27 SAST 2000.
Summary of my perl5 (5.0 patchlevel 5 subversion 3) configuration:
Platform:
osname=freebsd, osvers=4.0-current, archname=i386-freebsd
uname='FreeBSD freefall.FreeBSD.org 4.0-current FreeBSD 4.0-current #0: $Date$'
hint=recommended, useposix=true, d_sigaction=define
usethreads=undef useperlio=undef d_sfio=undef
Compiler:
cc='cc', optimize='undef', gccversion=2.95.2 19991024 (release)
cppflags=''
ccflags =''
stdchar='char', d_stdstdio=undef, usevfork=true
intsize=4, longsize=4, ptrsize=4, doublesize=8
d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
alignbytes=4, usemymalloc=n, prototype=define
Linker and Libraries:
ld='cc', ldflags ='-Wl,-E -lperl -lm '
libpth=/usr/lib
libs=-lm -lc -lcrypt
libc=, so=so, useshrplib=true, libperl=libperl.so.3
Dynamic Linking:
dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags=' -Wl,-R/usr/lib'
cccdlflags='-DPIC -fpic', lddlflags='-Wl,-E -shared -lperl -lm '
Locally applied patches:
---
@INC for perl 5.00503:
/usr/libdata/perl/5.00503/mach
/usr/libdata/perl/5.00503
/usr/local/lib/perl5/site_perl/5.005/i386-freebsd
/usr/local/lib/perl5/site_perl/5.005
.
---
Environment for perl 5.00503:
HOME=/usr/home/johny
LANG (unset)
LANGUAGE (unset)
LD_LIBRARY_PATH (unset)
LOGDIR (unset)
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/games:/usr/local/bin:/usr/X11R6/bin:/usr/home/johny
PERL_BADLANG (unset)
SHELL=/usr/local/bin/tcsh
Thread Next
-
[perl #24176] inconsistent m/.../g behaviour
by Jonathan Eisler