SPUG: Strange regex problem

Trevor Leffler tleffler at u.washington.edu
Fri Sep 22 11:04:24 CDT 2000


  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!

# //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!

#  Whoops!  //gi is acting fishy...
bash$ perl -e '$foo = "abcdefghijklmnopqrstuvwxyz"; $foo =~
s/(hi)(.*)(stu)/$3$2$1/gi; print "$1, $3!\n$foo\n"'
, !

Thanks for any light you can shed on this,
Trevor Leffler, Software Developer
PETTT, University of Washington
Box 353080, (206) 616-3406 FAX: (206) 616-2873

bash$ perl -V
Summary of my perl5 (5.0 patchlevel 5 subversion 3) configuration:
    osname=linux, osvers=2.2.5-22smp, archname=i386-linux
    uname='linux porky.devel.redhat.com 2.2.5-22smp #1 smp wed jun 2
09:11:51 edt 1999 i686 unknown '
    hint=recommended, useposix=true, d_sigaction=define
    usethreads=undef useperlio=undef d_sfio=undef
    cc='cc', optimize='-O2 -m486 -fno-strength-reduce',
gccversion=egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)   
cppflags='-Dbool=char -DHAS_BOOL -I/usr/local/include'
    ccflags ='-Dbool=char -DHAS_BOOL -I/usr/local/include'
    stdchar='char', d_stdstdio=undef, usevfork=false
    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 =' -L/usr/local/lib'
    libpth=/usr/local/lib /lib /usr/lib
    libs=-lnsl -ldl -lm -lc -lposix -lcrypt
    libc=, 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): 
  Built under linux
  Compiled at Aug 10 2000 15:33:00

 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     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