Closed p5pRT closed 11 years ago
This is a bug report for perl from 1@c07.de\, generated with the help of perlbug 1.34 running under perl v5.8.0.
perl -we 'my %h; @h{qw"a b c"}= 1..3; print for keys %h'
prints
Scalar value @h{qw"a b c"} better written as $h{qw"a b c"} at -e line 1.
Similar with other uncommon delimiters for qw: "'"\, "$"\, "-" and alphanumeric (maybe more).
Flags: category=core severity=low
Site configuration information for perl v5.8.0:
Configured by root at Sun Jul 27 08:17:01 CEST 2003.
Summary of my perl5 (revision 5.0 version 8 subversion 0) configuration: Platform: osname=linux\, osvers=2.4.20-gentoo-r2\, archname=i686-linux uname='linux local 2.4.20-gentoo-r2 #2 wed mar 26 00:29:00 cet 2003 i686 amd duron(tm) processor authenticamd gnulinux ' config_args='-des -Darchname=i686-linux -Dcc=gcc -Dprefix=/usr -Dvendorprefix=/usr -Dsiteprefix=/usr -Dlocincpth= -Doptimize=-pipe -march=athlon-tbird -O2 -frename-registers -fomit-frame-pointer -Duselargefiles -Dd_dosuid -Dd_semctl_semun -Dscriptdir=/usr/bin -Dman3ext=3pm -Dcf_by=Gentoo -Ud_csh -Di_gdbm -Di_db -Di_ndbm' hint=recommended\, useposix=true\, d_sigaction=define usethreads=undef use5005threads=undef useithreads=undef usemultiplicity=undef useperlio=define d_sfio=undef uselargefiles=define usesocks=undef use64bitint=undef use64bitall=undef uselongdouble=undef usemymalloc=n\, bincompat5005=undef Compiler: cc='gcc'\, ccflags ='-DPERL5 -fno-strict-aliasing -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64'\, optimize='-pipe -march=athlon-tbird -O2 -frename-registers -fomit-frame-pointer'\, cppflags='-DPERL5 -DPERL5 -fno-strict-aliasing' ccversion=''\, gccversion='3.2.3 20030422 (Gentoo Linux 1.4 3.2.3-r1\, propolice)'\, gccosandvers='' intsize=4\, longsize=4\, ptrsize=4\, doublesize=8\, byteorder=1234 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\, prototype=define Linker and Libraries: ld='gcc'\, ldflags =' -L/usr/local/lib' libpth=/usr/local/lib /lib /usr/lib libs=-lpthread -lnsl -lndbm -lgdbm -ldb -ldl -lm -lc -lcrypt -lutil perllibs=-lpthread -lnsl -ldl -lm -lc -lcrypt -lutil libc=/lib/libc-2.3.2.so\, so=so\, useshrplib=false\, libperl=libperl.a gnulibc_version='2.3.2' 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: /etc/perl /usr/lib/perl5/site_perl/5.8.0/i686-linux /usr/lib/perl5/site_perl/5.8.0 /usr/lib/perl5/site_perl /usr/lib/perl5/vendor_perl/5.8.0/i686-linux /usr/lib/perl5/vendor_perl/5.8.0 /usr/lib/perl5/vendor_perl /usr/lib/perl5/5.8.0/i686-linux /usr/lib/perl5/5.8.0 /usr/local/lib/site_perl .
Environment for perl v5.8.0: HOME=/home/cl LANG=C LANGUAGE (unset) LD_LIBRARY_PATH (unset) LOGDIR (unset)
PATH=.:/bin:/usr/bin:/usr/local/bin:/opt/bin:/usr/i686-pc-linux-gnu/gcc-bin/3.3:/opt/Acrobat5:/usr/X11R6/bin:/opt/sun-jdk-1.4.2.01/bin:/opt/sun-jdk-1.4.2.01/jre/bin:/opt/sun-jdk-1.4.2.01/jre/javaws:/usr/qt/3/bin:/usr/kde/3.1/bin PERL_BADLANG (unset) SHELL=/bin/bash
On 2004-04-08\, at 19:47:49 -0000\, Andreas Schneider (via RT) wrote:
# New Ticket Created by Andreas Schneider # Please include the string: [perl #28380] # in the subject line of all future correspondence about this issue. # \<URL: http://rt.perl.org:80/rt3/Ticket/Display.html?id=28380 >
This is a bug report for perl from 1@c07.de\, generated with the help of perlbug 1.34 running under perl v5.8.0.
perl -we 'my %h; @h{qw"a b c"}= 1..3; print for keys %h'
prints
Scalar value @h{qw"a b c"} better written as $h{qw"a b c"} at -e line 1.
Similar with other uncommon delimiters for qw: "'"\, "$"\, "-" and alphanumeric (maybe more).
And this doesn't warn\, even though it should:
perl -we 'my %h; @h{"a\,b\,c"}= 1..3'
I've looked at the code that triggers the warning\, and it's not more than a simple heuristic. It works quite well in the most common cases\, but fails in the above cases.
Marcus
--- Flags: category=core severity=low --- Site configuration information for perl v5.8.0:
Configured by root at Sun Jul 27 08:17:01 CEST 2003.
Summary of my perl5 (revision 5.0 version 8 subversion 0) configuration: Platform: osname=linux\, osvers=2.4.20-gentoo-r2\, archname=i686-linux uname='linux local 2.4.20-gentoo-r2 #2 wed mar 26 00:29:00 cet 2003 i686 amd duron(tm) processor authenticamd gnulinux ' config_args='-des -Darchname=i686-linux -Dcc=gcc -Dprefix=/usr -Dvendorprefix=/usr -Dsiteprefix=/usr -Dlocincpth= -Doptimize=-pipe -march=athlon-tbird -O2 -frename-registers -fomit-frame-pointer -Duselargefiles -Dd_dosuid -Dd_semctl_semun -Dscriptdir=/usr/bin -Dman3ext=3pm -Dcf_by=Gentoo -Ud_csh -Di_gdbm -Di_db -Di_ndbm' hint=recommended\, useposix=true\, d_sigaction=define usethreads=undef use5005threads=undef useithreads=undef usemultiplicity=undef useperlio=define d_sfio=undef uselargefiles=define usesocks=undef use64bitint=undef use64bitall=undef uselongdouble=undef usemymalloc=n\, bincompat5005=undef Compiler: cc='gcc'\, ccflags ='-DPERL5 -fno-strict-aliasing -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64'\, optimize='-pipe -march=athlon-tbird -O2 -frename-registers -fomit-frame-pointer'\, cppflags='-DPERL5 -DPERL5 -fno-strict-aliasing' ccversion=''\, gccversion='3.2.3 20030422 (Gentoo Linux 1.4 3.2.3-r1\, propolice)'\, gccosandvers='' intsize=4\, longsize=4\, ptrsize=4\, doublesize=8\, byteorder=1234 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\, prototype=define Linker and Libraries: ld='gcc'\, ldflags =' -L/usr/local/lib' libpth=/usr/local/lib /lib /usr/lib libs=-lpthread -lnsl -lndbm -lgdbm -ldb -ldl -lm -lc -lcrypt -lutil perllibs=-lpthread -lnsl -ldl -lm -lc -lcrypt -lutil libc=/lib/libc-2.3.2.so\, so=so\, useshrplib=false\, libperl=libperl.a gnulibc_version='2.3.2' 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: /etc/perl /usr/lib/perl5/site_perl/5.8.0/i686-linux /usr/lib/perl5/site_perl/5.8.0 /usr/lib/perl5/site_perl /usr/lib/perl5/vendor_perl/5.8.0/i686-linux /usr/lib/perl5/vendor_perl/5.8.0 /usr/lib/perl5/vendor_perl /usr/lib/perl5/5.8.0/i686-linux /usr/lib/perl5/5.8.0 /usr/local/lib/site_perl .
--- Environment for perl v5.8.0: HOME=/home/cl LANG=C LANGUAGE (unset) LD_LIBRARY_PATH (unset) LOGDIR (unset)
PATH=.:/bin:/usr/bin:/usr/local/bin:/opt/bin:/usr/i686-pc-linux-gnu/gcc-bin/3.3:/opt/Acrobat5:/usr/X11R6/bin:/opt/sun-jdk-1.4.2.01/bin:/opt/sun-jdk-1.4.2.01/jre/bin:/opt/sun-jdk-1.4.2.01/jre/javaws:/usr/qt/3/bin:/usr/kde/3.1/bin PERL_BADLANG (unset) SHELL=/bin/bash
-- Lackland's Laws: (1) Never be first. (2) Never be last. (3) Never volunteer for anything
The RT System itself - Status changed from 'new' to 'open'
Bogus warning with strawberry 5.8.9\, when making a list using qw'...'or qw"..." (but not any other characters) Also in a freshly compiled 5.8.9. And in cygwin's 5.10.1.
Whatever identifies scalar values and generates the warning is simply mistaken here\, possibly not prepared for qw changing the meaning of $quot; and '.
C:\thing>perl -wce "eval {@X{qw(abc def ghi)} = @{[1..99]}[37\,22\,1]}" Name "main::X" used only once: possible typo at -e line 1. -e syntax OK
C:\thing>perl -wce "eval {@X{qw'abc def ghi'} = @{[1..99]}[37\,22\,1]}" Scalar value @X{qw'abc def ghi'} better written as $X{qw'abc def ghi'} at -e line 1. Name "main::X" used only once: possible typo at -e line 1. -e syntax OK
C:\thing>perl -wle "eval {@X{qw'abc def ghi'} = @{[1..99]}[37\,22\,1]}; print join 'X'\, keys %X" Scalar value @X{qw'abc def ghi'} better written as $X{qw'abc def ghi'} at -e line 1. defXabcXghi
On Thu\, Apr 29\, 2010 at 01:20:13PM -0700\, David Nicol wrote:
# New Ticket Created by David Nicol # Please include the string: [perl #74782] # in the subject line of all future correspondence about this issue. # \<URL: http://rt.perl.org/rt3/Ticket/Display.html?id=74782 >
Bogus warning with strawberry 5.8.9\, when making a list using qw'...'or qw"..." (but not any other characters) Also in a freshly compiled 5.8.9. And in cygwin's 5.10.1.
Whatever identifies scalar values and generates the warning is simply mistaken here\, possibly not prepared for qw changing the meaning of $quot; and '.
The problem isn't qw specifically\, other constructions can cause the same warning:
perl -wce 'sub foo() { qw/abc def ghi/ } @X{+foo} = ( 1 .. 3 );' Scalar value @X{+foo} better written as $X{+foo} at -e line 1. Name "main::X" used only once: possible typo at -e line 1.
perl -we '$_ = "abc"; @X{split ""} = ( 1 .. 3 );' Scalar value @X{split ""} better written as $X{split ""} at -e line 1.
And other characters can be used with qw:
perl -we '@X{qw$abc def ghi$} = ( 1 .. 3 )' Scalar value @X{qw$abc def ghi$} better written as $X{qw$abc def ghi$} at -e line 1.
The code that produces the warning uses a fairly simple heuristic to try and detect incorrect usage of @foo[...] or @foo{...} - it scans for the closing ] or }\, skipping alphanumeric characters and a few others.
I don't really see a way to fix this without moving it up to checking the generated ops.
Tony
The RT System itself - Status changed from 'new' to 'open'
I'm trying to use hash slices\, but I get a warning saying Scalar value @foo{qw#a b#} better written as $foo{qw#a b#} at -e line 1. - this seems incorrect
This works OK:
geedorah:/home/wstest# perl -E '$foo{a}=1; $foo{b}=2; say join"\,"\, @foo{qw#a b#}' 1\,2
But with warnings:
geedorah:/home/wstest# perl -wE '$foo{a}=1; $foo{b}=2; say join"\,"\, @foo{qw#a b#}' Scalar value @foo{qw#a b#} better written as $foo{qw#a b#} at -e line 1. 1\,2
But if I take perl's advice\, it (unsurprisingly) doesn't work:
geedorah:/home/wstest# perl -wE '$foo{a}=1; $foo{b}=2; say join"\,"\, $foo{qw#a b#}' Use of uninitialized value within %foo in join or string at -e line 1.
Not using "qw" seems OK:
geedorah:/home/wstest# perl -wE '$foo{a}=1; $foo{b}=2; say join"\,"\, @foo{"a"\,"b"}' 1\,2
From http://www.perlmonks.org/?node_id=901368
I also confirmed the warning message (I'm on v5.12.2). But\, it only seems to happen with the # delimiters. If I use other delimiters\, I get no warnings:
$ perl -wE '$foo{a}=1; $foo{b}=2; say join"\,"\, @foo{qw{a b}}' 1\,2 $ perl -wE '$foo{a}=1; $foo{b}=2; say join"\,"\, @foo{qw/a b/}' 1\,2 $ perl -wE '$foo{a}=1; $foo{b}=2; say join"\,"\, @foo{qw(a b)}' 1\,2 $ perl -wE '$foo{a}=1; $foo{b}=2; say join"\,"\, @foo{qw#a b#}' Scalar value @foo{qw#a b#} better written as $foo{qw#a b#} at -e line 1. 1\,2 $
$ perl -c -we'my %f; my @a = @f{qw( a b )}' -e syntax OK
$ perl -c -we'my %f; my @a = @f{qw! a b !}' -e syntax OK
$ perl -c -we'my %f; my @a = @f{qw# a b #}' Scalar value @f{qw# a b #} better written as $f{qw# a b #} at -e line 1. -e syntax OK
$ perl -c -we'my %f; my @a = @f{qw$ a b $}' Scalar value @f{qw$ a b $} better written as $f{qw$ a b $} at -e line 1. -e syntax OK
Bug present in all versions tested: v5.8.9\, v5.10.1\, v5.12.2\, v5.13.10.
There's all manner of fun one can have here\, this warns on the perfectly valid\, but why-would-you fragments below:
the perldev/perl% ./miniperl -w -e 'my %f; my @s = @f{"}"\, "a"}' Scalar value @f{"} better written as $f{"} at -e line 1.
the perldev/perl% ./miniperl -w -e 'my %f; my @s = @f{"]"\, "a"}' Scalar value @f{"] better written as $f{"] at -e line 1.
I've attached a patch for a failing test as I can't solve this quickly.
The offensive code is from toke.c which just looks to the first closing } or ] in a vague way for a sort-of-scalar or a sort-of-list within the braces:
/* Warn about @ where they meant $. */ if (*s == '[' || *s == '{') { if (ckWARN(WARN_SYNTAX)) { const char *t = s + 1; while (*t && (isALNUM_lazy_if(t\,UTF) || strchr(" \t$#+-'\""\, *t))) t++; if (*t == '}' || *t == ']') { t++; PL_bufptr = PEEKSPACE(PL_bufptr); /* XXX can realloc */ Perl_warner(aTHX_ packWARN(WARN_SYNTAX)\, "Scalar value %.*s better written as $%.*s"\, (int)(t-PL_bufptr)\, PL_bufptr\, (int)(t-PL_bufptr-1)\, PL_bufptr+1); } } }
diff --git a/t/lib/warnings/toke b/t/lib/warnings/toke index 9c33e71..622441a 100644 --- a/t/lib/warnings/toke +++ b/t/lib/warnings/toke @@ -972\,3 +972\,15 @@ Regexp modifiers "/l" and "/a" are mutually exclusive at - line 4\, near "= " Regexp modifier "/l" may not appear twice at - line 5\, near "= " Regexp modifier "/a" may appear a maximum of twice at - line 7\, near "= " BEGIN not safe after errors--compilation aborted at - line 8. +######## +# toke.c +use warnings; +my %f; +my @a = @f{qw(a b)}; +@a = @f{qw$a b$}; +@a = @f{"}"\, "a"}; +print "done\n"; +my $a = @f{q'a'}; +EXPECT +Scalar value @f{q'a'} better written as $f{q'a'} at - line 8. +done
The RT System itself - Status changed from 'new' to 'open'
Except\, of course\, I meant to send you this test patch. Sorry.
Alex
On Sat Apr 30 22:52:59 2011\, quidity wrote:
There's all manner of fun one can have here\, this warns on the perfectly valid\, but why-would-you fragments below:
the perldev/perl% ./miniperl -w -e 'my %f; my @s = @f{"}"\, "a"}' Scalar value @f{"} better written as $f{"} at -e line 1.
the perldev/perl% ./miniperl -w -e 'my %f; my @s = @f{"]"\, "a"}' Scalar value @f{"] better written as $f{"] at -e line 1.
I've attached a patch for a failing test as I can't solve this quickly.
The offensive code is from toke.c which just looks to the first closing } or ] in a vague way for a sort-of-scalar or a sort-of-list within the braces:
/\* Warn about @​ where they meant $\. \*/ if \(\*s == '\[' || \*s == '\{'\) \{ if \(ckWARN\(WARN\_SYNTAX\)\) \{ const char \*t = s \+ 1; while \(\*t && \(isALNUM\_lazy\_if\(t\,UTF\) || strchr\("
\t$#+-'\""\, *t))) t++; if (*t == '}' || *t == ']') { t++; PL_bufptr = PEEKSPACE(PL_bufptr); /* XXX can realloc */ Perl_warner(aTHX_ packWARN(WARN_SYNTAX)\, "Scalar value %.*s better written as $%.*s"\, (int)(t-PL_bufptr)\, PL_bufptr\, (int)(t-PL_bufptr-1)\, PL_bufptr+1); } } }
diff --git a/t/lib/warnings/toke b/t/lib/warnings/toke index 9c33e71..6cdff28 100644 --- a/t/lib/warnings/toke +++ b/t/lib/warnings/toke @@ -972\,3 +972\,15 @@ Regexp modifiers "/l" and "/a" are mutually exclusive at - line 4\, near "= " Regexp modifier "/l" may not appear twice at - line 5\, near "= " Regexp modifier "/a" may appear a maximum of twice at - line 7\, near "= " BEGIN not safe after errors--compilation aborted at - line 8. +######## +# toke.c +use warnings; +my %f; +my @a = @f{qw(a b)}; +@a = @f{qw$a b$}; +@a = @f{"}"\, "a"}; +print "done\n"; +my $a = @f{q'a'}; +EXPECT +done +Scalar value @f{q'a'} better written as $f{q'a'} at - line 8.
No\, I didn't. Warnings first\, done last. As you were. The first patch is the correct one.
On Sat Apr 30 22:57:59 2011\, quidity wrote:
Except\, of course\, I meant to send you this test patch. Sorry.
Alex
On Sat Apr 30 22:52:59 2011\, quidity wrote:
There's all manner of fun one can have here\, this warns on the perfectly valid\, but why-would-you fragments below:
the perldev/perl% ./miniperl -w -e 'my %f; my @s = @f{"}"\, "a"}' Scalar value @f{"} better written as $f{"} at -e line 1.
the perldev/perl% ./miniperl -w -e 'my %f; my @s = @f{"]"\, "a"}' Scalar value @f{"] better written as $f{"] at -e line 1.
I've attached a patch for a failing test as I can't solve this quickly.
The offensive code is from toke.c which just looks to the first closing } or ] in a vague way for a sort-of-scalar or a sort-of-list within the braces:
/\* Warn about @​ where they meant $\. \*/ if \(\*s == '\[' || \*s == '\{'\) \{ if \(ckWARN\(WARN\_SYNTAX\)\) \{ const char \*t = s \+ 1; while \(\*t && \(isALNUM\_lazy\_if\(t\,UTF\) || strchr\("
\t$#+-'\""\, *t))) t++; if (*t == '}' || *t == ']') { t++; PL_bufptr = PEEKSPACE(PL_bufptr); /* XXX can realloc */ Perl_warner(aTHX_ packWARN(WARN_SYNTAX)\, "Scalar value %.*s better written as $%.*s"\, (int)(t-PL_bufptr)\, PL_bufptr\, (int)(t-PL_bufptr-1)\, PL_bufptr+1); } } }
The following code
perl -Mwarnings -E"@x{qw'y z'}"
elicits the warning
Scalar value @x{qw'y z'} better written as $x{qw'y z'} at -e line 1.
which is clearly bogus and following the recommendation would break code logic. This does not happen with @x{(qw'y z')} or another delimiter for qq.
The issue has been confirmed on freenode #perl channel.
Fixed in 429a25554.
--
Father Chrysostomos
Fixed in 429a25554.
--
Father Chrysostomos
@cpansprout - Status changed from 'open' to 'resolved'
Migrated from rt.perl.org#28380 (status was 'resolved')
Searchable as RT28380$