Module: —
Description
I am comparing the length of a string. It happened to be undefined but the warning was misleading and made me think the logic of my comparison was broken. The warning reads like my code was missing parenthesis and compiled into length( $x == 0 )
which it didn’t.
I think this was probably discussed before and I am not the first to bring this up but googling this yields a ton of posts about low quality code which produced the warning and users trying to figure out its basic meaning.
Steps to Reproduce
$ perl -wE 'my $x; say( (length $x) == 0 )' Use of uninitialized value $x in numeric eq (==) at -e line 1. 1
The warning is incorrect: not $x
is compared but length($x)
. I confirmed this behavior for
abs($x)
length($x)
delete()
on hash keys:$ perl -wE 'my %h; say( delete $h{foo} == 0 )' Use of uninitialized value $h{"foo"} in numeric eq (==) at -e line 1. 1
Expected behavior
It’s probably hard to implement a generic representation of the expression. So any of those:
Use of uninitialized value length($x) in numeric eq (==)
(I think, it might be possible as it looks like there is already special handling for core functions.)Use of uninitialized value $x in length
Use of uninitialized value in numeric eq (==)
like for user-defined functions:$ perl -wE 'sub f{shift} my $x; say( f($x) == 0 )' Use of uninitialized value in numeric eq (==) at -e line 1. 1
Perl configuration
Summary of my perl5 (revision 5 version 38 subversion 0) configuration:
Platform:
osname=linux
osvers=5.10.0-25-amd64
archname=x86_64-linux-thread-multi
uname='linux berlin 5.10.0-25-amd64 #1 smp debian 5.10.191-1 (2023-08-16) x86_64 gnulinux '
config_args='-de -Dprefix=/home/daniel/perl5/perlbrew/perls/perl-5.38.0-threads-bullseye -Dusethreads -Aeval:scriptdir=/home/daniel/perl5/perlbrew/perls/perl-5.38.0-threads-bullseye/bin'
hint=recommended
useposix=true
d_sigaction=define
useithreads=define
usemultiplicity=define
use64bitint=define
use64bitall=define
uselongdouble=undef
usemymalloc=n
default_inc_excludes_dot=define
Compiler:
cc='cc'
ccflags ='-D_REENTRANT -D_GNU_SOURCE -fwrapv -fno-strict-aliasing -pipe -fstack-protector-strong -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -D_FORTIFY_SOURCE=2'
optimize='-O2'
cppflags='-D_REENTRANT -D_GNU_SOURCE -fwrapv -fno-strict-aliasing -pipe -fstack-protector-strong -I/usr/local/include'
ccversion=''
gccversion='10.2.1 20210110'
gccosandvers=''
intsize=4
longsize=8
ptrsize=8
doublesize=8
byteorder=12345678
doublekind=3
d_longlong=define
longlongsize=8
d_longdbl=define
longdblsize=16
longdblkind=3
ivtype='long'
ivsize=8
nvtype='double'
nvsize=8
Off_t='off_t'
lseeksize=8
alignbytes=8
prototype=define
Linker and Libraries:
ld='cc'
ldflags =' -fstack-protector-strong -L/usr/local/lib'
libpth=/usr/local/lib /usr/lib/x86_64-linux-gnu /usr/lib /usr/lib64
libs=-lpthread -ldl -lm -lcrypt -lutil -lc
perllibs=-lpthread -ldl -lm -lcrypt -lutil -lc
libc=libc-2.31.so
so=so
useshrplib=false
libperl=libperl.a
gnulibc_version='2.31'
Dynamic Linking:
dlsrc=dl_dlopen.xs
dlext=so
d_dlsymun=undef
ccdlflags='-Wl,-E'
cccdlflags='-fPIC'
lddlflags='-shared -O2 -L/usr/local/lib -fstack-protector-strong'
Characteristics of this binary (from libperl):
Compile-time options:
HAS_LONG_DOUBLE
HAS_STRTOLD
HAS_TIMES
MULTIPLICITY
PERLIO_LAYERS
PERL_COPY_ON_WRITE
PERL_DONT_CREATE_GVSV
PERL_HASH_FUNC_SIPHASH13
PERL_HASH_USE_SBOX32
PERL_MALLOC_WRAP
PERL_OP_PARENT
PERL_PRESERVE_IVUV
PERL_USE_SAFE_PUTENV
USE_64_BIT_ALL
USE_64_BIT_INT
USE_ITHREADS
USE_LARGE_FILES
USE_LOCALE
USE_LOCALE_COLLATE
USE_LOCALE_CTYPE
USE_LOCALE_NUMERIC
USE_LOCALE_TIME
USE_PERLIO
USE_PERL_ATOF
USE_REENTRANT_API
USE_THREAD_SAFE_LOCALE
Built under linux
Compiled at Sep 1 2023 12:51:38
%ENV:
PERLBREW_HOME="/home/daniel/.perlbrew"
PERLBREW_MANPATH="/home/daniel/perl5/perlbrew/perls/perl-5.38.0-threads-bullseye/man"
PERLBREW_PATH="/home/daniel/perl5/perlbrew/bin:/home/daniel/perl5/perlbrew/perls/perl-5.38.0-threads-bullseye/bin"
PERLBREW_PERL="perl-5.38.0-threads-bullseye"
PERLBREW_ROOT="/home/daniel/perl5/perlbrew"
PERLBREW_SHELLRC_VERSION="0.92"
PERLBREW_VERSION="0.92"
@INC:
/home/daniel/perl5/perlbrew/perls/perl-5.38.0-threads-bullseye/lib/site_perl/5.38.0/x86_64-linux-thread-multi
/home/daniel/perl5/perlbrew/perls/perl-5.38.0-threads-bullseye/lib/site_perl/5.38.0
/home/daniel/perl5/perlbrew/perls/perl-5.38.0-threads-bullseye/lib/5.38.0/x86_64-linux-thread-multi
/home/daniel/perl5/perlbrew/perls/perl-5.38.0-threads-bullseye/lib/5.38.0
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4