Closed p5pRT closed 20 years ago
If variable interpolation takes place in a regular expression\, perl seems to consider lexical variables in (?{ code }) construct as global variables.
The following little script exhibits the problem:
#! /usr/local/bin/perl -w
use strict; use re 'eval';
my ($a\, $x\, $y) = ('a'\, 0\, 0); $_ = 'a';
# No variable interpolation occurs in RE. # This will print "$x=1" as expected. / a (?{ $x = 1 }) /xo and print "\$x=$x\n";
# A variable interpolation occurs in RE. # This will print "$y=0\, $::y=1" which seems to be a bug. / $a (?{ $y = 1 }) /xo and print "\$y=$y\, \$::y=$::y\n";
The output is:
Name "main::y" used only once: possible typo at ./rebug.pl line 15. $x=1 \<-- seems OK $y=0\, $::y=1 \<-- seems wrong
Both $x and $y are lexical\, but when evaluating the second RE\, assignment is done to the global variable $::y.
I also checked with 5.00563\, and got the same result.
This perlbug was built using Perl 5.00503 - Wed May 19 12:05:03 JST 1999 It is being executed now by Perl 5.00563 - Tue Jan 25 12:05:18 JST 2000.
Site configuration information for perl 5.00503:
Configured by ishisone at Wed May 19 12:05:03 JST 1999.
Summary of my perl5 (5.0 patchlevel 5 subversion 3) configuration: Platform: osname=freebsd\, osvers=2.2.8-release\, archname=i386-freebsd uname='freebsd srapc459.sra.co.jp 2.2.8-release freebsd 2.2.8-release #0: fri apr 16 11:14:40 jst 1999 ishisone@srapc459.sra.co.jp:usrsrcsyscompilesrapc459_slim i386 ' hint=previous\, useposix=true\, d_sigaction=define usethreads=undef useperlio=undef d_sfio=undef Compiler: cc='cc'\, optimize='-O'\, gccversion=2.7.2.1 cppflags='-I/usr/local/include' ccflags ='-I/usr/local/include' 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='ld'\, ldflags =' -L/usr/local/lib' libpth=/usr/local/lib /usr/lib libs=-lm -lxpg4 -lc -lcrypt libc=/usr/lib/libc.so.3.1\, so=so\, useshrplib=false\, libperl=libperl.a Dynamic Linking: dlsrc=dl_dlopen.xs\, dlext=so\, d_dlsymun=undef\, ccdlflags=' ' cccdlflags='-DPIC -fpic'\, lddlflags='-Bshareable -L/usr/local/lib'
Locally applied patches:
@INC for perl 5.00503: /amd/a/srapc451/mnt3/home/mgr/ishisone/lib/perl5 /usr/local/lib/perl5/5.00503/i386-freebsd /usr/local/lib/perl5/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=/amd/a/srapc451/mnt3/home/mgr/ishisone LANG=ja_JP.EUC LANGUAGE (unset) LC_COLLATE=C LC_TIME=C LD_LIBRARY_PATH (unset) LOGDIR (unset) PATH=/amd/a/srapc451/mnt3/home/mgr/ishisone/bin:/amd/a/srapc451/mnt3/home/mgr/ishisone/bin/i386-freebsd2:/usr/X11R6/bin:/usr/local/bin:/usr/local/sbin:/usr/sra/bin:/usr/local/tdoc/bin:/usr/local/emacs/bin:/usr/new/mh:/usr/local/bin/mh:/usr/local/v6/bin:/usr/local/v6/sbin:/usr/ucb:/usr/bin:/usr/new:/bin:/etc:/usr/etc:/usr/sbin:/sbin:/amd/a/srapc451/mnt3/home/mgr/ishisone/bin/lastresort: PERL5LIB=/amd/a/srapc451/mnt3/home/mgr/ishisone/lib/perl5 PERL_BADLANG (unset) SHELL=/usr/local/bin/bash
Makoto Ishisone writes:
If variable interpolation takes place in a regular expression\, perl seems to consider lexical variables in (?{ code }) construct as global variables.
Thanks. This is a known problem. You pinpointed the conditions it happens under absolutely correct. But nobody could fix it...
Ilya
Migrated from rt.perl.org#2030 (status was 'resolved')
Searchable as RT2030$