Perl / perl5

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

qw() gives different results in 5.6 to previous versions #1817

Closed p5pRT closed 20 years ago

p5pRT commented 24 years ago

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

Searchable as RT3080$

p5pRT commented 24 years ago

From @gbarr

Created by gbarr@chipper.localdomain

During the change to make qw() compile time the interpretation of the contents seems to have changed too.

$ perl5.00503 -le 'print qw{ (?​:\\\\.|[^\\\\()]+)* }' (?​:\\.|[^\\()]+)*

$ perl5.6.0 -le 'print qw{ (?​:\\\\.|[^\\\\()]+)* }' (?​:\\\\.|[^\\\\()]+)*

Perl Info ``` Flags: category=core severity=high Site configuration information for perl v5.6.0: Configured by gbarr at Wed Mar 29 16:49:13 BST 2000. Summary of my perl5 (revision 5.0 version 6 subversion 0) configuration: Platform: osname=linux, osvers=2.2.13, archname=i686-linux uname='linux chipper 2.2.13 #1 mon nov 8 15:37:25 cet 1999 i686 unknown ' config_args='-des' 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='-O2', gccversion=egcs-2.91.66 19990314/Linux (egcs-1.1.2 release) cppflags='-fno-strict-aliasing -I/usr/local/include' ccflags ='-fno-strict-aliasing -I/usr/local/include -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 -lndbm -lgdbm -ldbm -ldb -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' Locally applied patches: @INC for perl v5.6.0: /home/value/perl /usr/local/lib/perl5/5.6.0/i686-linux /usr/local/lib/perl5/5.6.0 /usr/local/lib/perl5/site_perl/5.6.0/i686-linux /usr/local/lib/perl5/site_perl/5.6.0 /usr/local/lib/perl5/site_perl . Environment for perl v5.6.0: HOME=/home/gbarr LANG=POSIX LANGUAGE (unset) LD_LIBRARY_PATH (unset) LOGDIR (unset) PATH=/home/gbarr/bin:/usr/local/bin:/usr/bin:/usr/X11R6/bin:/bin:/usr/games/bin:/usr/games:/opt/gnome/bin:/opt/kde/bin:. PERL5LIB=/home/value/perl PERL_BADLANG (unset) SHELL=/usr/bin/zsh ```
p5pRT commented 24 years ago

From [Unknown Contact. See original ticket]

During the change to make qw() compile time the interpretation of the contents seems to have changed too.

$ perl5.00503 -le 'print qw{ (?​:\\\\.|[^\\\\()]+)* }' (?​:\\.|[^\\()]+)*

$ perl5.6.0 -le 'print qw{ (?​:\\\\.|[^\\\\()]+)* }' (?​:\\\\.|[^\\\\()]+)*

Whoa. So instead of just being a compile-time list\, you get TRUE single-quoted context? Have you tried doing

  qw( this \) that )

I'm just curious because the only other place you can get 0 interpolation like that is in a single-quoted here-document.

p5pRT commented 24 years ago

From @gbarr

On Tue\, Apr 11\, 2000 at 08​:39​:51AM -0400\, Jeff Pinyan wrote​:

During the change to make qw() compile time the interpretation of the contents seems to have changed too.

$ perl5.00503 -le 'print qw{ (?​:\\\\.|[^\\\\()]+)* }' (?​:\\.|[^\\()]+)*

$ perl5.6.0 -le 'print qw{ (?​:\\\\.|[^\\\\()]+)* }' (?​:\\\\.|[^\\\\()]+)*

Whoa. So instead of just being a compile-time list\, you get TRUE single-quoted context? Have you tried doing

qw( this \) that )

That gives the same answer with both versions of perl

$ perl5.00503 -le 'print qw( this \) that )' this)that

$ perl5.6.0 -le 'print qw( this \) that )' this)that

But

$ perl5.6.0 -le 'print qw{ this \) that }' this\)that

$ perl5.00503 -le 'print qw{ this \) that }' this\)that

And

$ perl5.00503 -le 'print qw{ this \\ that }' this\that

$ perl5.6.0 -le 'print qw{ this \\ that }' this\\that

$ perl5.00503 -le 'print qw( this \\ that )' this\that

$ perl5.6.0 -le 'print qw( this \\ that )' this\\that

This is because inside qw() the only time a \ is dropped is if the following character is the delimeter character. Obviously this was not the case in 5.00305\, but I don't have the source here to check.

Graham.

p5pRT commented 24 years ago

From [Unknown Contact. See original ticket]

Graham Barr \gbarr@​dhcp69\.uk\.valueclick\.com wrote

During the change to make qw() compile time the interpretation of the contents seems to have changed too.

$ perl5.00503 -le 'print qw{ (?​:\\\\.|[^\\\\()]+)* }' (?​:\\.|[^\\()]+)*

$ perl5.6.0 -le 'print qw{ (?​:\\\\.|[^\\\\()]+)* }' (?​:\\\\.|[^\\\\()]+)*

Clearly a bug\, since both 5.005_03 and 5.6.0\, in their own ways\, say that the argument to qw{} is subject to q{} quoting​:

-------------- 5.005_03 ----------------------   It is exactly equivalent to

  split(' '\, q/STRING/);


-------------- 5.6.0 ----------------------   It can be understood as being roughly   equivalent to​:

  split(' '\, q/STRING/);

  the difference being that it generates a real list   at compile time. So this expression​:

  qw(foo bar baz)

  is semantically equivalent to the list​:

  'foo'\, 'bar'\, 'baz'


Neither quote is entirely honest with respect to delimiters\, but I guess it's near enough.

Mike Guy

p5pRT commented 24 years ago

From @gsar

On Wed\, 12 Apr 2000 15​:11​:36 BST\, "M.J.T. Guy" wrote​:

Graham Barr \gbarr@​dhcp69\.uk\.valueclick\.com wrote

During the change to make qw() compile time the interpretation of the contents seems to have changed too.

$ perl5.00503 -le 'print qw{ (?​:\\\\.|[^\\\\()]+)* }' (?​:\\.|[^\\()]+)*

$ perl5.6.0 -le 'print qw{ (?​:\\\\.|[^\\\\()]+)* }' (?​:\\\\.|[^\\\\()]+)*

Clearly a bug\, since both 5.005_03 and 5.6.0\, in their own ways\, say that the argument to qw{} is subject to q{} quoting​:

Agreed. I think the KEY_qw processing in toke.c is missing the moral equivalent of calling tokeq(PL_lex_stuff). Patch welcome.

Sarathy gsar@​ActiveState.com

p5pRT commented 24 years ago

From [Unknown Contact. See original ticket]

In message \200004142343\.QAA05204@​maul\.ActiveState\.com   Gurusamy Sarathy \gsar@​ActiveState\.com wrote​:

On Wed\, 12 Apr 2000 15​:11​:36 BST\, "M.J.T. Guy" wrote​:

Graham Barr \gbarr@​dhcp69\.uk\.valueclick\.com wrote

$ perl5.6.0 -le 'print qw{ (?​:\\\\.|[^\\\\()]+)* }' (?​:\\\\.|[^\\\\()]+)*

Clearly a bug\, since both 5.005_03 and 5.6.0\, in their own ways\, say that the argument to qw{} is subject to q{} quoting​:

Agreed. I think the KEY_qw processing in toke.c is missing the moral equivalent of calling tokeq(PL_lex_stuff). Patch welcome.

Patch attached.

Tom

-- Tom Hughes (tom@​compton.nu) http​://www.compton.nu/ ...It now costs more to amuse a child than it once did to educate his father.

p5pRT commented 24 years ago

From [Unknown Contact. See original ticket]

perl.qw.patch ```diff # This is a patch for perl-5.6.0 to update it to perl-qw # # To apply this patch: # STEP 1: Chdir to the source directory. # STEP 2: Run the 'applypatch' program with this patch file as input. # # If you do not have 'applypatch', it is part of the 'makepatch' package # that you can fetch from the Comprehensive Perl Archive Network: # http://www.perl.com/CPAN/authors/Johan_Vromans/makepatch-x.y.tar.gz # In the above URL, 'x' should be 2 or higher. # # To apply this patch without the use of 'applypatch': # STEP 1: Chdir to the source directory. # STEP 2: Run the 'patch' program with this file as input. # #### End of Preamble #### #### Patch data follows #### diff -c 'perl-5.6.0/t/op/misc.t' 'perl-qw/t/op/misc.t' Index: ./t/op/misc.t *** ./t/op/misc.t Sun Mar 12 20:00:29 2000 --- ./t/op/misc.t Sat Apr 15 16:50:37 2000 *************** *** 545,547 **** --- 545,551 ---- lcfirst - world uc - WORLD lc - world + ######## + print qw(ab a\b a\\b); + EXPECT + aba\ba\b diff -c 'perl-5.6.0/toke.c' 'perl-qw/toke.c' Index: ./toke.c *** ./toke.c Sat Apr 1 18:39:08 2000 --- ./toke.c Sat Apr 15 16:33:18 2000 *************** *** 4495,4501 **** for (; !isSPACE(*d) && len; --len, ++d) ; } words = append_elem(OP_LIST, words, ! newSVOP(OP_CONST, 0, newSVpvn(b, d-b))); } } if (words) { --- 4495,4501 ---- for (; !isSPACE(*d) && len; --len, ++d) ; } words = append_elem(OP_LIST, words, ! newSVOP(OP_CONST, 0, tokeq(newSVpvn(b, d-b)))); } } if (words) { #### End of Patch data #### #### ApplyPatch data follows #### # Data version : 1.0 # Date generated : Sat Apr 15 16:59:53 2000 # Generated by : makepatch 2.00 # Recurse directories : Yes # v 'patchlevel.h' 3025 955811999 33060 # p 't/op/misc.t' 11036 955813837 0100555 # p 'toke.c' 182447 955812798 0100444 #### End of ApplyPatch data #### #### End of Patch kit [created: Sat Apr 15 16:59:53 2000] #### #### Checksum: 66 1969 8724 #### ```