SPUG: Strange regex problem
Matt Tucker
tuck at whistlingfish.net
Fri Sep 22 12:50:52 CDT 2000
-- Trevor Leffler <tleffler at u.washington.edu> spake thusly:
> I'm working with a substitution regex that correctly does a
> substitution, but the $1, $2, etc. that I expect are empty when I use
> the //i and //g modifiers together. I am hoping that one of you may
> have seen this before and have a good explanation; why would they
> react to one another? Please ignore that the //i and //g are
> pointless in my example, except for demonstrating this problem. Here
> is an example of what I'm talking about (using the ever-so-cute abc
> regex):
>
> # Just using //i here
> bash$ perl -e '$foo = "abcdefghijklmnopqrstuvwxyz"; $foo =~
> s/(hi)(.*)(stu)/$3$2$1/i; print "$1, $3!\n$foo\n"'
> hi, stu!
> abcdefgstujklmnopqrhivwxyz
>
> # //g here, and still no problems with $1, $2, and $3
> bash$ perl -e '$foo = "abcdefghijklmnopqrstuvwxyz"; $foo =~
> s/(hi)(.*)(stu)/$3$2$1/g; print "$1, $3!\n$foo\n"'
> hi, stu!
> abcdefgstujklmnopqrhivwxyz
>
> # Whoops! //gi is acting fishy...
> bash$ perl -e '$foo = "abcdefghijklmnopqrstuvwxyz"; $foo =~
> s/(hi)(.*)(stu)/$3$2$1/gi; print "$1, $3!\n$foo\n"'
> , !
> abcdefgstujklmnopqrhivwxyz
This seems to be fixed in 5.6:
[2] mtucker at benzene$ perl -e '$foo = "abcdefghijklmnopqrstuvwxyz"; $foo
=~ s/(hi)(.*)(stu)/$3$2$1/gi; print "$1, $3!\n$foo\n"'
hi, stu!
abcdefgstujklmnopqrhivwxyz
[3] mtucker at benzene$ perl -V
Summary of my perl5 (revision 5.0 version 6 subversion 0) configuration:
Platform:
osname=linux, osvers=2.2.15-0.16mdksmp, archname=i386-linux
uname='linux kenobi.mandrakesoft.com 2.2.15-0.16mdksmp #1 smp mon
mar 13 16:40:10 cet 2000 i686 unknown '
config_args='-des -Dprefix=/usr -Darchname=i386-linux -Dd_dosuid
-Dd_semctl_semun -Di_db -Di_ndbm -Di_gdbm -Ud_csh
-Dman3dir=/usr/lib/perl5/man/man3 -Doptimize=-O3 -fomit-frame-pointer
-fno-exceptions -fno-rtti -pipe -s -mpentium -mcpu=pentium
-march=pentium -ffast-math -fexpensive-optimizations'
hint=recommended, useposix=true, d_sigaction=define
usethreads=undef use5005threads=undef useithreads=undef
usemultiplicity=undef
useperlio=undef d_sfio=undef uselargefiles=define
use64bitint=undef use64bitall=undef uselongdouble=undef
usesocks=undef
Compiler:
cc='cc', optimize='-O3 -fomit-frame-pointer -fno-exceptions
-fno-rtti -pipe -s -mpentium -mcpu=pentium -march=pentium -ffast-math
-fexpensive-optimizations', gccversion=2.95.3 19991030 (prerelease)
cppflags='-fno-strict-aliasing'
ccflags ='-fno-strict-aliasing -D_LARGEFILE_SOURCE
-D_FILE_OFFSET_BITS=64'
stdchar='char', d_stdstdio=define, usevfork=false
intsize=4, longsize=4, ptrsize=4, doublesize=8
d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t',
lseeksize=8
alignbytes=4, usemymalloc=n, prototype=define
Linker and Libraries:
ld='cc', ldflags =' -L/usr/local/lib'
libpth=/usr/local/lib /lib /usr/lib
libs=-lnsl -ldl -lm -lc -lposix -lcrypt
libc=/lib/libc-2.1.3.so, so=so, useshrplib=false, libperl=libperl.a
Dynamic Linking:
dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-rdynamic'
cccdlflags='-fpic', lddlflags='-shared -L/usr/local/lib'
Characteristics of this binary (from libperl):
Compile-time options: USE_LARGE_FILES
Built under linux
Compiled at Mar 28 2000 16:22:07
%ENV:
PERL5LIB="/home/mtucker/lib"
@INC:
/home/mtucker/lib
/usr/lib/perl5/5.6.0/i386-linux
/usr/lib/perl5/5.6.0
/usr/lib/perl5/site_perl/5.6.0/i386-linux
/usr/lib/perl5/site_perl/5.6.0
/usr/lib/perl5/site_perl/5.005/i386-linux
/usr/lib/perl5/site_perl/5.005
/usr/lib/perl5/site_perl
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
POST TO: spug-list at pm.org PROBLEMS: owner-spug-list at pm.org
Subscriptions; Email to majordomo at pm.org: ACTION LIST EMAIL
Replace ACTION by subscribe or unsubscribe, EMAIL by your Email-address
For daily traffic, use spug-list for LIST ; for weekly, spug-list-digest
Seattle Perl Users Group (SPUG) Home Page: http://www.halcyon.com/spug/
More information about the spug-list
mailing list