Perl / perl5

🐪 The Perl programming language
https://dev.perl.org/perl5/
Other
1.92k stars 549 forks source link

Regex vars after a while only existing if they have been "used" #6181

Closed p5pRT closed 16 years ago

p5pRT commented 21 years ago

Migrated from rt.perl.org#19388 (status was 'resolved')

Searchable as RT19388$

p5pRT commented 21 years ago

From perl-5.8.0@ton.iguana.be

Created by perl-5.8.0@ton.iguana.be

perl -wle '$_="bk"; print"_=$_\,1=$1" while s/((.))k$2//;print"|$1|"' Use of uninitialized value in concatenation (.) or string at -e line 1. _=\,1=b |b|

perl -wle '$_="bk"; print"_=$_" while s/((.))k$2//;print" $1 "' Use of uninitialized value in concatenation (.) or string at -e line 1. _= Use of uninitialized value in concatenation (.) or string at -e line 1.

As you can see $1 after the while only exists if it has been used during the loop.

Many other variants of this bug exist. e.g. finding the longest repeated substring (up to length 2**16) like this works​:

#!perl -l $_=pop;$?++\,!$&while/(.{$?})(?=.*\1)/;print$&

(notice the useless !$&) but fails like this​:

#!perl -l $_=pop;$?++while/(.{$?})(?=.*\1)/;print$&

Perl Info ``` Flags: category=core severity=low Site configuration information for perl v5.8.0: Configured by ton at Tue Nov 12 01:56:18 CET 2002. Summary of my perl5 (revision 5.0 version 8 subversion 0) configuration: Platform: osname=linux, osvers=2.4.19, archname=i686-linux-thread-multi-64int-ld uname='linux quasar 2.4.19 #5 wed oct 2 02:34:25 cest 2002 i686 unknown ' config_args='' hint=recommended, useposix=true, d_sigaction=define usethreads=define use5005threads=undef useithreads=define usemultiplicity=define useperlio=define d_sfio=undef uselargefiles=define usesocks=undef use64bitint=define use64bitall=undef uselongdouble=define usemymalloc=y, bincompat5005=undef Compiler: cc='cc', ccflags ='-D_REENTRANT -D_GNU_SOURCE -fno-strict-aliasing -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64', optimize='-O2 -fomit-frame-pointer', cppflags='-D_REENTRANT -D_GNU_SOURCE -fno-strict-aliasing -I/usr/local/include' ccversion='', gccversion='2.95.3 20010315 (release)', gccosandvers='' intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=12345678 d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12 ivtype='long long', ivsize=8, nvtype='long double', nvsize=12, Off_t='off_t', lseeksize=8 alignbytes=4, prototype=define Linker and Libraries: ld='cc', ldflags =' -L/usr/local/lib' libpth=/usr/local/lib /lib /usr/lib libs=-lnsl -lndbm -ldb -ldl -lm -lpthread -lc -lposix -lcrypt -lutil perllibs=-lnsl -ldl -lm -lpthread -lc -lposix -lcrypt -lutil libc=/lib/libc-2.2.4.so, so=so, useshrplib=false, libperl=libperl.a gnulibc_version='2.2.4' Dynamic Linking: dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-rdynamic' cccdlflags='-fpic', lddlflags='-shared -L/usr/local/lib' Locally applied patches: @INC for perl v5.8.0: /usr/lib/perl5/5.8.0/i686-linux-thread-multi-64int-ld /usr/lib/perl5/5.8.0 /usr/lib/perl5/site_perl/5.8.0/i686-linux-thread-multi-64int-ld /usr/lib/perl5/site_perl/5.8.0 /usr/lib/perl5/site_perl . Environment for perl v5.8.0: HOME=/home/ton LANG (unset) LANGUAGE (unset) LD_LIBRARY_PATH (unset) LOGDIR (unset) PATH=/home/ton/bin.Linux:/home/ton/bin:/home/ton/bin.SampleSetup:/usr/local/bin:/usr/local/sbin:/usr/local/jre/bin:/home/oracle/product/9.0.1/bin:/usr/local/ar/bin:/usr/games/bin:/usr/X11R6/bin:/usr/share/bin:/usr/bin:/usr/sbin:/bin:/sbin:. PERL_BADLANG (unset) SHELL=/bin/bash ```
p5pRT commented 16 years ago

From renee.baecker@smart-websolutions.de

The behaviour changed in Perl 5.10​:

reneeb@​reneeb-desktop​:\~$ /opt/perl510/bin/perl -wle '$_ = "bk"; print "_=$_" while s/((.))k$2//;print " $1 "' Use of uninitialized value $2 in regexp compilation at -e line 1. _= Use of uninitialized value $1 in concatenation (.) or string at -e line 1.
reneeb@​reneeb-desktop​:\~$ /opt/perl510/bin/perl -wle '$_ = "bk"; print "_=$_\,1=$1" while s/((.))k$2//;print " $1 "' Use of uninitialized value $2 in regexp compilation at -e line 1. _=\,1=b Use of uninitialized value $1 in concatenation (.) or string at -e line 1.

reneeb@​reneeb-desktop​:\~$

Cheers\, Renee

p5pRT commented 16 years ago

The RT System itself - Status changed from 'new' to 'open'

p5pRT commented 16 years ago

@rgs - Status changed from 'open' to 'resolved'