Front page | perl.perl5.porters |
Postings from October 2003
[perl #24212] non-defined -x tests behaviour unexpected ( "-1" eq -F 1' )
Thread Next
From:
David Dyck
Date:
October 14, 2003 18:07
Subject:
[perl #24212] non-defined -x tests behaviour unexpected ( "-1" eq -F 1' )
Message ID:
rt-24212-66049.2.3864566020616@rt.perl.org
# New Ticket Created by David Dyck
# Please include the string: [perl #24212]
# in the subject line of all future correspondence about this issue.
# <URL: http://rt.perl.org/rt2/Ticket/Display.html?id=24212 >
This is a bug report for perl from david.dyck@fluke.com,
generated with the help of perlbug 1.34 running under perl v5.9.0.
-----------------------------------------------------------------
[Please enter your report here]
I had a error in some code the other day, when
I intended to code -f but instead I entered -F.
To my surprise, I didn't get an error or warning.
After reading toke.c in the perl sources, I see
the following comment when the letter after the '-' in -x
is not one those listed in perldoc -f -x
/* Assume it was a minus followed by a one-letter named
* subroutine call (or a -bareword), then. */
In perlop.pod
Unary "-" performs arithmetic negation if the operand is numeric. If the
operand is an identifier, a string consisting of a minus sign concatenated
with the identifier is returned. Otherwise, if the string starts with a
plus or minus, a string starting with the opposite sign is returned. One
effect of these rules is that "-bareword" is equivalent to "-bareword".
[ perhaps the text above could be written differently, as
"-bareword" is alwasy equal to "-bareword", (I do see that
the pod source encodes this differently, as
C<-bareword> is equivalent to C<"-bareword">
which in html displays as
-bareword is equivalent to "-bareword". ]
Anyway, I expect that perl should give me an error, a warning,
or return a bareword converted string, but in the following
examples perl is definitely DWIM'ing
If I create a one-letter subroutine I see that the sub is not called:
$ perl -wle 'use strict; print -F 1'
-1
And the -F is not converted to a -bareword
$ perl -wle 'use strict; print -F 1'
-1
$ perl -wle 'use strict; print "strange" if "-1" eq -F 1'
strange
The follow scripts reports the set of letters where -x doesn't
do what I expect.
e.g. strange -X codes: DEFGHIJKLNOPQUVYZahijmnoqvy
#!/usr/local/bin/perl -w
use strict;
no strict 'refs';
use B::Deparse;
my $d=B::Deparse->new();
my $q = "1";
my @testlist = ("a" .."z", "A" .. "Z");
my %strange;
for my $x (@testlist) {
my $s = "{\n -$x \$q;\n}";
my $sr = eval "sub $s";
warn "$@" if length $@;
my $dp = $d->coderef2text( $sr );
if ($s ne $dp) {
print "expect:\n$s\ndeparse returned:\n$dp\n";
++$strange{$x}
}
}
print "strange -X codes: ",join( "", sort keys %strange), "\n";
__END__
[Please do not change anything below this line]
-----------------------------------------------------------------
---
Flags:
category=core
severity=low
---
Site configuration information for perl v5.9.0:
Configured by dcd at Tue Oct 7 12:13:57 PDT 2003.
Summary of my perl5 (revision 5.0 version 9 subversion 0 patch 21419) configuration:
Platform:
osname=linux, osvers=2.4.23pre1, archname=i686-linux
uname='linux dd 2.4.23pre1 #2 wed aug 27 11:20:37 pdt 2003 i686 '
config_args='-Dmksymlinks -Dinstallusrbinperl -Uversiononly -Dusedevel -Doptimize=-O3 -g -de -Dcf_email=david.dyck@fluke.com'
hint=recommended, useposix=true, d_sigaction=define
usethreads=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='cc', ccflags ='-DDEBUGGING -fno-strict-aliasing -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
optimize='-O3 -g',
cppflags='-DDEBUGGING -fno-strict-aliasing -I/usr/local/include'
ccversion='', gccversion='egcs-2.91.66.1 19990314/Linux (egcs-1.1.2 release)', 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=4
alignbytes=4, prototype=define
Linker and Libraries:
ld='cc', ldflags =' -L/usr/local/lib'
libpth=/usr/local/lib /lib /usr/lib
libs=-lgdbm -ldbm -ldb -ldl -lm -lc
perllibs=-ldl -lm -lc
libc=/lib/libc.so.5.4.44, so=so, useshrplib=false, libperl=libperl.a
gnulibc_version=''
Dynamic Linking:
dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-rdynamic'
cccdlflags='-fpic', lddlflags='-shared -L/usr/local/lib'
Locally applied patches:
DEVEL21398
---
@INC for perl v5.9.0:
/usr/local/lib/perl5/5.9.0/i686-linux
/usr/local/lib/perl5/5.9.0
/usr/local/lib/perl5/site_perl/5.9.0/i686-linux
/usr/local/lib/perl5/site_perl/5.9.0
/usr/local/lib/perl5/site_perl/5.8.0/i686-linux
/usr/local/lib/perl5/site_perl/5.8.0
/usr/local/lib/perl5/site_perl
.
---
Environment for perl v5.9.0:
HOME=/home/dcd
LANG (unset)
LANGUAGE (unset)
LD_LIBRARY_PATH (unset)
LOGDIR (unset)
PATH=/home/dcd/bin:/sbin:/usr/local/bin:/bin:/usr/bin:/usr/X11/bin:/usr/games:/usr/local/samba:/home/hobbes/tools/scripts:/home/hobbes/tools/linux:/usr0/hobbes/tools/scripts:/usr0/dcd/bin:/apps/general/bin:/usr/public
PERL5_CPANPLUS_CONFIG=/home/dcd/.cpanplus/config
PERL_BADLANG (unset)
SHELL=/bin/bash
Thread Next
-
[perl #24212] non-defined -x tests behaviour unexpected ( "-1" eq -F 1' )
by David Dyck