Perl / perl5

šŸŖ The Perl programming language
https://dev.perl.org/perl5/
Other
1.96k stars 555 forks source link

perldiag.pod on defined %hash #11520

Closed p5pRT closed 13 years ago

p5pRT commented 13 years ago

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

Searchable as RT95538$

p5pRT commented 13 years ago

From user42@zip.com.au

I found the perldiag.pod description of item "defined(%hash) is deprecated" unclear.

At first I thought it was threatening another incompatible change\, but if I'm not mistaken it's merely that defined %hash has only ever been a check for non-empty\, which may not be what you intended. If so then perhaps a wording like the following could make it clearer\,

(D deprecated) C\<defined()> is not usually useful on hashes\, it merely checks for non-empty\, similar to a hash in boolean context (see L\). If a non-empty check is what you want then just use

  if (%hash) {   # not empty   }

If you had C\<defined(%Foo​::Bar​::QUUX)> to check whether such a package variable exists\, then it has never actually done that\, but instead creates the hash if necessary (autovivification) then tests for non-empty. If you really want to check existence of a package variable then look at the glob slot with C\<defined *Foo​::Bar​::QUUX{HASH}> (see L\).

Perl Info ``` Flags: category=library severity=medium module=Math::BigRat Site configuration information for perl 5.12.4: Configured by Debian Project at Tue Jun 28 22:20:03 UTC 2011. Summary of my perl5 (revision 5 version 12 subversion 4) configuration: Derived from: Platform: osname=linux, osvers=2.6.32-5-686, archname=i486-linux-gnu-thread-multi-64int uname='linux callisto 2.6.32-5-686 #1 smp mon jun 13 04:13:06 utc 2011 i686 gnulinux ' config_args='-Dusethreads -Duselargefiles -Dccflags=-DDEBIAN -Dcccdlflags=-fPIC -Darchname=i486-linux-gnu -Dprefix=/usr -Dprivlib=/usr/share/perl/5.12 -Darchlib=/usr/lib/perl/5.12 -Dvendorprefix=/usr -Dvendorlib=/usr/share/perl5 -Dvendorarch=/usr/lib/perl5 -Dsiteprefix=/usr/local -Dsitelib=/usr/local/share/perl/5.12.4 -Dsitearch=/usr/local/lib/perl/5.12.4 -Dman1dir=/usr/share/man/man1 -Dman3dir=/usr/share/man/man3 -Dsiteman1dir=/usr/local/man/man1 -Dsiteman3dir=/usr/local/man/man3 -Duse64bitint -Dman1ext=1 -Dman3ext=3perl -Dpager=/usr/bin/sensible-pager -Uafs -Ud_csh -Ud_ualarm -Uusesfio -Uusenm -Ui_libutil -DDEBUGGING=-g -Doptimize=-O2 -Duseshrplib -Dlibperl=libperl.so.5.12.4 -des' hint=recommended, useposix=true, d_sigaction=define useithreads=define, usemultiplicity=define useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef use64bitint=define, use64bitall=undef, uselongdouble=undef usemymalloc=n, bincompat5005=undef Compiler: cc='cc', ccflags ='-D_REENTRANT -D_GNU_SOURCE -DDEBIAN -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64', optimize='-O2 -g', cppflags='-D_REENTRANT -D_GNU_SOURCE -DDEBIAN -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include' ccversion='', gccversion='4.6.1', 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='double', nvsize=8, Off_t='off_t', lseeksize=8 alignbytes=4, prototype=define Linker and Libraries: ld='cc', ldflags =' -fstack-protector -L/usr/local/lib' libpth=/usr/local/lib /lib /usr/lib /usr/lib/i386-linux-gnu /usr/lib64 libs=-lgdbm -lgdbm_compat -ldb -ldl -lm -lpthread -lc -lcrypt perllibs=-ldl -lm -lpthread -lc -lcrypt libc=, so=so, useshrplib=true, libperl=libperl.so.5.12.4 gnulibc_version='2.13' Dynamic Linking: dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E' cccdlflags='-fPIC', lddlflags='-shared -O2 -g -L/usr/local/lib -fstack-protector' ```
p5pRT commented 13 years ago

From @cpansprout

On Sun Jul 24 17​:05​:39 2011\, kryde wrote​:

I found the perldiag.pod description of item "defined(%hash) is deprecated" unclear.

At first I thought it was threatening another incompatible change\, but if I'm not mistaken it's merely that defined %hash has only ever been a check for non-empty\,

Actually\, it used to return false for a hash that had never had anything in it\, but true for hash that had been empty after having something in it. But it interfered with the implementation\, so it was deprecated and subsequently changed.

In any case\, your version is better\, so Iā€™ve applied it\, with tweaks\, as commit 16546e4. Thank you.

which may not be what you intended. If so then perhaps a wording like the following could make it clearer\,

(D deprecated) C\<defined()> is not usually useful on hashes\, it merely checks for non-empty\, similar to a hash in boolean context (see L\). If a non-empty check is what you want then just use

if \(%hash\) \{
   \# not empty
\}

If you had C\<defined(%Foo​::Bar​::QUUX)> to check whether such a package variable exists\, then it has never actually done that\, but instead creates the hash if necessary (autovivification) then tests for non-empty. If you really want to check existence of a package variable then look at the glob slot with C\<defined *Foo​::Bar​::QUUX{HASH}> (see L\).

[Please do not change anything below this line] ----------------------------------------------------------------- --- Flags​: category=library severity=medium module=Math​::BigRat --- Site configuration information for perl 5.12.4​:

Configured by Debian Project at Tue Jun 28 22​:20​:03 UTC 2011.

Summary of my perl5 (revision 5 version 12 subversion 4) configuration​: Derived from​: Platform​: osname=linux\, osvers=2.6.32-5-686\, archname=i486-linux-gnu-thread- multi-64int uname='linux callisto 2.6.32-5-686 #1 smp mon jun 13 04​:13​:06 utc 2011 i686 gnulinux ' config_args='-Dusethreads -Duselargefiles -Dccflags=-DDEBIAN -Dcccdlflags=-fPIC -Darchname=i486-linux-gnu -Dprefix=/usr -Dprivlib=/usr/share/perl/5.12 -Darchlib=/usr/lib/perl/5.12 -Dvendorprefix=/usr -Dvendorlib=/usr/share/perl5 -Dvendorarch=/usr/lib/perl5 -Dsiteprefix=/usr/local -Dsitelib=/usr/local/share/perl/5.12.4 -Dsitearch=/usr/local/lib/perl/5.12.4 -Dman1dir=/usr/share/man/man1 -Dman3dir=/usr/share/man/man3 -Dsiteman1dir=/usr/local/man/man1 -Dsiteman3dir=/usr/local/man/man3 -Duse64bitint -Dman1ext=1 -Dman3ext=3perl -Dpager=/usr/bin/sensible-pager -Uafs -Ud_csh -Ud_ualarm -Uusesfio -Uusenm -Ui_libutil -DDEBUGGING=-g -Doptimize=-O2 -Duseshrplib -Dlibperl=libperl.so.5.12.4 -des' hint=recommended\, useposix=true\, d_sigaction=define useithreads=define\, usemultiplicity=define useperlio=define\, d_sfio=undef\, uselargefiles=define\, usesocks=undef use64bitint=define\, use64bitall=undef\, uselongdouble=undef usemymalloc=n\, bincompat5005=undef Compiler​: cc='cc'\, ccflags ='-D_REENTRANT -D_GNU_SOURCE -DDEBIAN -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64'\, optimize='-O2 -g'\, cppflags='-D_REENTRANT -D_GNU_SOURCE -DDEBIAN -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include' ccversion=''\, gccversion='4.6.1'\, 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='double'\, nvsize=8\, Off_t='off_t'\, lseeksize=8 alignbytes=4\, prototype=define Linker and Libraries​: ld='cc'\, ldflags =' -fstack-protector -L/usr/local/lib' libpth=/usr/local/lib /lib /usr/lib /usr/lib/i386-linux-gnu /usr/lib64 libs=-lgdbm -lgdbm_compat -ldb -ldl -lm -lpthread -lc -lcrypt perllibs=-ldl -lm -lpthread -lc -lcrypt libc=\, so=so\, useshrplib=true\, libperl=libperl.so.5.12.4 gnulibc_version='2.13' Dynamic Linking​: dlsrc=dl_dlopen.xs\, dlext=so\, d_dlsymun=undef\, ccdlflags='-Wl\,-E' cccdlflags='-fPIC'\, lddlflags='-shared -O2 -g -L/usr/local/lib -fstack-protector'

p5pRT commented 13 years ago

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

p5pRT commented 13 years ago

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

p5pRT commented 13 years ago

From @cpansprout

On Sun Jul 24 21​:13​:54 2011\, sprout wrote​:

On Sun Jul 24 17​:05​:39 2011\, kryde wrote​:

I found the perldiag.pod description of item "defined(%hash) is deprecated" unclear.

At first I thought it was threatening another incompatible change\, but if I'm not mistaken it's merely that defined %hash has only ever been a check for non-empty\,

Actually\, it used to return false for a hash that had never had anything in it\, but true for hash that had been empty after having something in it. But it interfered with the implementation\, so it was deprecated and subsequently changed.

In any case\, your version is better\, so Iā€™ve applied it\, with tweaks\, as commit 16546e4. Thank you.

Oops! Iā€™ve just realised that it *still* does that maybe-defined thing with empty hashes. What I was thinking of was the hack to make defined() return false on empty stashes\, even when the implementation had changed underneath. Now stashes are always defined. So this will need rewording. I donā€™t know if Iā€™ll get to it soon. Will you have a chance?

In case you donā€™t understand what Iā€™m saying\, run this one-liner​:

perl -Xle 'print defined %foo; %foo = (1\,2); %foo=(); print defined %foo;

which may not be what you intended. If so then perhaps a wording like the following could make it clearer\,

(D deprecated) C\<defined()> is not usually useful on hashes\, it merely checks for non-empty\, similar to a hash in boolean context (see L\). If a non-empty check is what you want then just use

if \(%hash\) \{
   \# not empty
\}

If you had C\<defined(%Foo​::Bar​::QUUX)> to check whether such a package variable exists\, then it has never actually done that\, but instead creates the hash if necessary (autovivification) then tests for non-empty. If you really want to check existence of a package variable then look at the glob slot with C\<defined *Foo​::Bar​::QUUX{HASH}> (see L\).

[Please do not change anything below this line] ----------------------------------------------------------------- --- Flags​: category=library severity=medium module=Math​::BigRat --- Site configuration information for perl 5.12.4​:

Configured by Debian Project at Tue Jun 28 22​:20​:03 UTC 2011.

Summary of my perl5 (revision 5 version 12 subversion 4) configuration​: Derived from​: Platform​: osname=linux\, osvers=2.6.32-5-686\, archname=i486-linux-gnu-thread- multi-64int uname='linux callisto 2.6.32-5-686 #1 smp mon jun 13 04​:13​:06 utc 2011 i686 gnulinux ' config_args='-Dusethreads -Duselargefiles -Dccflags=-DDEBIAN -Dcccdlflags=-fPIC -Darchname=i486-linux-gnu -Dprefix=/usr -Dprivlib=/usr/share/perl/5.12 -Darchlib=/usr/lib/perl/5.12 -Dvendorprefix=/usr -Dvendorlib=/usr/share/perl5 -Dvendorarch=/usr/lib/perl5 -Dsiteprefix=/usr/local -Dsitelib=/usr/local/share/perl/5.12.4 -Dsitearch=/usr/local/lib/perl/5.12.4 -Dman1dir=/usr/share/man/man1 -Dman3dir=/usr/share/man/man3 -Dsiteman1dir=/usr/local/man/man1 -Dsiteman3dir=/usr/local/man/man3 -Duse64bitint -Dman1ext=1 -Dman3ext=3perl -Dpager=/usr/bin/sensible-pager -Uafs -Ud_csh -Ud_ualarm -Uusesfio -Uusenm -Ui_libutil -DDEBUGGING=-g -Doptimize=-O2 -Duseshrplib -Dlibperl=libperl.so.5.12.4 -des' hint=recommended\, useposix=true\, d_sigaction=define useithreads=define\, usemultiplicity=define useperlio=define\, d_sfio=undef\, uselargefiles=define\, usesocks=undef use64bitint=define\, use64bitall=undef\, uselongdouble=undef usemymalloc=n\, bincompat5005=undef Compiler​: cc='cc'\, ccflags ='-D_REENTRANT -D_GNU_SOURCE -DDEBIAN -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64'\, optimize='-O2 -g'\, cppflags='-D_REENTRANT -D_GNU_SOURCE -DDEBIAN -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include' ccversion=''\, gccversion='4.6.1'\, 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='double'\, nvsize=8\, Off_t='off_t'\, lseeksize=8 alignbytes=4\, prototype=define Linker and Libraries​: ld='cc'\, ldflags =' -fstack-protector -L/usr/local/lib' libpth=/usr/local/lib /lib /usr/lib /usr/lib/i386-linux-gnu /usr/lib64 libs=-lgdbm -lgdbm_compat -ldb -ldl -lm -lpthread -lc -lcrypt perllibs=-ldl -lm -lpthread -lc -lcrypt libc=\, so=so\, useshrplib=true\, libperl=libperl.so.5.12.4 gnulibc_version='2.13' Dynamic Linking​: dlsrc=dl_dlopen.xs\, dlext=so\, d_dlsymun=undef\, ccdlflags='-Wl\,-E' cccdlflags='-fPIC'\, lddlflags='-shared -O2 -g -L/usr/local/lib -fstack-protector'

p5pRT commented 13 years ago

From @rurban

This is a bug report for perl from rurban@​x-ray.at\, generated with the help of perlbug 1.39 running under perl 5.15.0.

From 1488bb1ec6b4881b38296a0aeebb2f20327ff30c Mon Sep 17 00​:00​:00 2001 From​: Reini Urban \rurban@&#8203;x\-ray\.at Date​: Sun\, 24 Jul 2011 20​:07​:37 +0200 Subject​: [PATCH] fix outdated url to dtrace blog post MIME-Version​: 1.0 Content-Type​: multipart/mixed; boundary="------------1.7.6"

This is a multi-part message in MIME format. --------------1.7.6 Content-Type​: text/plain; charset=UTF-8; format=fixed Content-Transfer-Encoding​: 8bit


perldtrace.d | 2 +- 1 files changed\, 1 insertions(+)\, 1 deletions(-)

--------------1.7.6 Content-Type​: text/x-patch; name="0001-fix-outdated-url-to-dtrace-blog-post.patch" Content-Transfer-Encoding​: 8bit Content-Disposition​: attachment; filename="0001-fix-outdated-url-to-dtrace-blog-post.patch"

Inline Patch ```diff diff --git a/perldtrace.d b/perldtrace.d index 6040d2b..f87a27a 100644 --- a/perldtrace.d +++ b/perldtrace.d @@ -1,6 +1,6 @@ /* * Written by Alan Burlinson -- taken from his blog post - * at . + * at . */ provider perl { --------------1.7.6-- --- ```

Flags:   category=docs   severity=low


Site configuration information for perl 5.15.0​:

Configured by rurban at Sun Jul 3 19​:30​:23 CEST 2011.

Summary of my perl5 (revision 5 version 15 subversion 0) configuration​:   Commit id​: 961bfa8c285ba0f3c125df699f8fc2cdae21ddd5   Platform​:   osname=cygwin\, osvers=1.7.9(0.23753)\, archname=cygwin-64int   uname='cygwin_nt-5.1 reini 1.7.9(0.23753) 2011-03-29 10​:10 i686 cygwin '   config_args='-de -Dlibperl=cygperl5_15_0d-nt@​961bfa8c.dll -Dcc=gcc-4 -Dld=g++-4 -Accflags=-march=pentium4 -Accflags=-mfpmath=sse -Accflags=-mieee-fp -Accflags=-mmmx -Accflags=-msse -Accflags=-msse2 -Dmksymlinks -Uusethreads -Dmad=y -Dusedevel -Dstatic_ext=Cwd -DDEBUGGING -Doptimize=-g3'   hint=recommended\, useposix=true\, d_sigaction=define   useithreads=undef\, usemultiplicity=undef   useperlio=define\, d_sfio=undef\, uselargefiles=define\, usesocks=undef   use64bitint=define\, use64bitall=undef\, uselongdouble=undef   usemymalloc=y\, bincompat5005=undef   Compiler​:   cc='gcc-4'\, ccflags ='-DPERL_USE_SAFE_PUTENV -U__STRICT_ANSI__ -march=pentium4 -mfpmath=sse -mieee-fp -mmmx -msse -msse2 -DDEBUGGING -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include'\,   optimize='-g3'\,   cppflags='-DPERL_USE_SAFE_PUTENV -U__STRICT_ANSI__ -march=pentium4 -mfpmath=sse -mieee-fp -mmmx -msse -msse2 -DDEBUGGING -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include'   ccversion=''\, gccversion='4.3.4 20090804 (release) 1'\, 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='double'\, nvsize=8\, Off_t='off_t'\, lseeksize=8   alignbytes=8\, prototype=define   Linker and Libraries​:   ld='g++-4'\, ldflags =' -Wl\,--enable-auto-import -Wl\,--export-all-symbols -Wl\,--enable-auto-image-base -fstack-protector -L/usr/local/lib'   libpth=/usr/local/lib /usr/lib /lib   libs=-lgdbm -ldb -ldl -lcrypt -lgdbm_compat   perllibs=-ldl -lcrypt   libc=/usr/lib/libc.a\, so=dll\, useshrplib=true\, libperl=cygperl5_15_0d-nt@​961bfa8c.dll   gnulibc_version=''   Dynamic Linking​:   dlsrc=dl_dlopen.xs\, dlext=dll\, d_dlsymun=undef\, ccdlflags=' '   cccdlflags=' '\, lddlflags=' --shared -Wl\,--enable-auto-import -Wl\,--export-all-symbols -Wl\,--enable-auto-image-base -L/usr/local/lib -fstack-protector'

Locally applied patches​:  


@​INC for perl 5.15.0​:   /usr/lib/perl5/site_perl/5.15.0/i686-nothreads-debug-cygwin-git   /usr/lib/perl5/site_perl/5.15.0   /usr/lib/perl5/vendor_perl/5.15.0/i686-nothreads-debug-cygwin-git   /usr/lib/perl5/vendor_perl/5.15.0   /usr/lib/perl5/5.15.0/i686-nothreads-debug-cygwin-git   /usr/lib/perl5/5.15.0   /usr/lib/perl5/site_perl   /usr/lib/perl5/vendor_perl   /usr/lib/perl5/site_perl/5.14.1   /usr/lib/perl5/site_perl/5.14   /usr/lib/perl5/site_perl/5.12   /usr/lib/perl5/site_perl/5.10   /usr/lib/perl5/vendor_perl/5.10   /usr/lib/perl5/site_perl/5.8   .


Environment for perl 5.15.0​:   HOME=/home/rurban   LANG=C.UTF-8   LANGUAGE (unset)   LD_LIBRARY_PATH (unset)   LOGDIR (unset)   PATH=~/bin​:/usr/bin​:/usr/sbin​:/usr/local/sbin​:/usr/local/bin​:/usr/bin​:/bin​:/usr/X11R6/bin​:\~/bin​:/usr/bin​:/usr/sbin​:/usr/local/sbin​:/usr/local/bin​:/usr/bin​:/bin​:/usr/X11R6/bin​:/cygdrive/c/Programme/PC Connectivity Solution​:/cygdrive/c/WINDOWS/system32​:/cygdrive/c/WINDOWS​:/usr/bin​:/cyg1/bin​:/cyg1/usr/local/bin​:/cygdrive/c/WINDOWS/System32/Wbem​:/cygdrive/c/Programme/ATI Technologies/ATI.ACE/Core-Static​:/cygdrive/c/Programme/Gemeinsame Dateien/Ulead Systems/MPEG​:/cygdrive/u​:/cygdrive/c/Programme/Perforce​:/cygdrive/c/Programme/QuickTime/QTSystem​:/usr/lib/lapack   PERL_BADLANG (unset)   SHELL=/bin/bash

p5pRT commented 13 years ago

From @cpansprout

On Sun Jul 24 21​:20​:19 2011\, sprout wrote​:

On Sun Jul 24 21​:13​:54 2011\, sprout wrote​:

On Sun Jul 24 17​:05​:39 2011\, kryde wrote​:

I found the perldiag.pod description of item "defined(%hash) is deprecated" unclear.

At first I thought it was threatening another incompatible change\, but if I'm not mistaken it's merely that defined %hash has only ever been a check for non-empty\,

Actually\, it used to return false for a hash that had never had anything in it\, but true for hash that had been empty after having something in it. But it interfered with the implementation\, so it was deprecated and subsequently changed.

In any case\, your version is better\, so Iā€™ve applied it\, with tweaks\, as commit 16546e4. Thank you.

Oops! Iā€™ve just realised that it *still* does that maybe-defined thing with empty hashes. What I was thinking of was the hack to make defined() return false on empty stashes\, even when the implementation had changed underneath. Now stashes are always defined. So this will need rewording. I donā€™t know if Iā€™ll get to it soon. Will you have a chance?

In case you donā€™t understand what Iā€™m saying\, run this one-liner​:

perl -Xle 'print defined %foo; %foo = (1\,2); %foo=(); print defined %foo;

Iā€™ve just fixed the first paragraph to be factually correct\, with commit 79b7f44.

What do you think of this?

(D deprecated) C\<defined()> is not usually useful on hashes\, because it is not a reliable check for anything. Sometimes it returns true on an empty hash\, and sometimes false. If a non-empty check is what you want then just use​:

p5pRT commented 13 years ago

From @cpansprout

On Sun Jul 24 22​:27​:32 2011\, rurban wrote​:

This is a bug report for perl from rurban@​x-ray.at\, generated with the help of perlbug 1.39 running under perl 5.15.0.

From 1488bb1ec6b4881b38296a0aeebb2f20327ff30c Mon Sep 17 00​:00​:00 2001 From​: Reini Urban \rurban@&#8203;x\-ray\.at Date​: Sun\, 24 Jul 2011 20​:07​:37 +0200 Subject​: [PATCH] fix outdated url to dtrace blog post MIME-Version​: 1.0 Content-Type​: multipart/mixed; boundary="------------1.7.6"

This is a multi-part message in MIME format. --------------1.7.6 Content-Type​: text/plain; charset=UTF-8; format=fixed Content-Transfer-Encoding​: 8bit

--- perldtrace.d | 2 +- 1 files changed\, 1 insertions(+)\, 1 deletions(-)

--------------1.7.6 Content-Type​: text/x-patch; name="0001-fix-outdated-url-to-dtrace- blog-post.patch" Content-Transfer-Encoding​: 8bit Content-Disposition​: attachment; filename="0001-fix-outdated-url-to- dtrace-blog-post.patch"

diff --git a/perldtrace.d b/perldtrace.d index 6040d2b..f87a27a 100644 --- a/perldtrace.d +++ b/perldtrace.d @​@​ -1\,6 +1\,6 @​@​ /* * Written by Alan Burlinson -- taken from his blog post - * at \<http​://blogs.sun.com/alanbur/date/20050909>. + * at \<http​://bleaklow.com/2005/09/09/dtrace_and_perl.html>. */

provider perl {

--------------1.7.6--

Thank you. Applied as 344c1cf. How did you end up attaching it to this ticket?

p5pRT commented 13 years ago

From [Unknown Contact. See original ticket]

On Sun Jul 24 22​:27​:32 2011\, rurban wrote​:

This is a bug report for perl from rurban@​x-ray.at\, generated with the help of perlbug 1.39 running under perl 5.15.0.

From 1488bb1ec6b4881b38296a0aeebb2f20327ff30c Mon Sep 17 00​:00​:00 2001 From​: Reini Urban \rurban@&#8203;x\-ray\.at Date​: Sun\, 24 Jul 2011 20​:07​:37 +0200 Subject​: [PATCH] fix outdated url to dtrace blog post MIME-Version​: 1.0 Content-Type​: multipart/mixed; boundary="------------1.7.6"

This is a multi-part message in MIME format. --------------1.7.6 Content-Type​: text/plain; charset=UTF-8; format=fixed Content-Transfer-Encoding​: 8bit

--- perldtrace.d | 2 +- 1 files changed\, 1 insertions(+)\, 1 deletions(-)

--------------1.7.6 Content-Type​: text/x-patch; name="0001-fix-outdated-url-to-dtrace- blog-post.patch" Content-Transfer-Encoding​: 8bit Content-Disposition​: attachment; filename="0001-fix-outdated-url-to- dtrace-blog-post.patch"

diff --git a/perldtrace.d b/perldtrace.d index 6040d2b..f87a27a 100644 --- a/perldtrace.d +++ b/perldtrace.d @​@​ -1\,6 +1\,6 @​@​ /* * Written by Alan Burlinson -- taken from his blog post - * at \<http​://blogs.sun.com/alanbur/date/20050909>. + * at \<http​://bleaklow.com/2005/09/09/dtrace_and_perl.html>. */

provider perl {

--------------1.7.6--

Thank you. Applied as 344c1cf. How did you end up attaching it to this ticket?

p5pRT commented 13 years ago

From user42@zip.com.au

"Father Chrysostomos via RT" \perlbug\-followup@&#8203;perl\.org writes​:

Actually\, it used to return false for a hash that had never had anything in it\, but true for hash that had been empty after having something in it.

That wouldn't be hard to keep\, for compatibility\, would it? Any hv_store() and friends set a flag ...

(D deprecated) C\<defined()> is not usually useful on hashes\, because it is not a reliable check for anything. Sometimes it returns true on an empty hash\, and sometimes false. If a non-empty check is what you want then just use​:

"Sometimes" there reads like it's random or something. What about describing what happens (or has happened) such as below. Knowing what the offending call has done will be important to anyone who's trying to change some code to avoid the message or understand it etc ...

(Though I'd still think the behaviour might easily enough be left alone\, in which case instead a description perlfunc.pod of the slight strangeness.)

(D deprecated) C\<defined()> is not usually the right thing for hashes. It returns true if a value has ever been stored in the hash (even if then emptied again). Depending on this has been discouraged since 5.005.

If a check for non-empty is what you want then just use boolean context (see L\<perldata/Scalar values>)

  if (%hash) {   # not empty   }

If you had C\<defined %Foo​::Bar​::QUUX> to check whether such a package variable exists then it has still only tested "ever stored to"\, which is probably not a reliable way to enquire about the features of a package\, or whether a package has been loaded\, etc.

p5pRT commented 13 years ago

From @cpansprout

On Sat Aug 06 01​:57​:12 2011\, kryde wrote​:

"Father Chrysostomos via RT" \perlbug\-followup@&#8203;perl\.org writes​:

Actually\, it used to return false for a hash that had never had anything in it\, but true for hash that had been empty after having something in it.

That wouldn't be hard to keep\, for compatibility\, would it? Any hv_store() and friends set a flag ...

(D deprecated) C\<defined()> is not usually useful on hashes\, because it is not a reliable check for anything. Sometimes it returns true on an empty hash\, and sometimes false. If a non-empty check is what you want then just use​:

"Sometimes" there reads like it's random or something. What about describing what happens (or has happened) such as below.

It *is* random. :-) OK\, you asked for it​:

Hashes have a C array (called HvARRAY) in which the buckets of the hash are stored. Originally\, the HvARRAY would only be allocated when something was about to be stored in the hash. defined(%foo) returns true when HvARRAY is not null. %foo = () clears all entries\, leaving HvARRAY in place. undef %foo originally would free HvARRAY as well\, setting it to null.

Later\, HvARRAY started being used to store other information as well (in the HvAUX structure which is part of the same allocated block)​:

1.Ā The name\, if it is a stash. So stashes are always defined.

2. The backreferences array. Try this​:

perl -MScalar​::Util=weaken -le '$x = \%foo; print defined %foo; weaken $x; print defined %foo'

3. The current iterator. So iterating over a hash may cause it suddenly to become defined​:

perl -MScalar​::Util=weaken -le 'print defined %foo; each %foo; print defined %foo'

(It seems iteration has always caused a hash to become defined\, actually.)

So now undef(%foo) doesnā€˜t always free HvARRAY\, as that would break weak references.

Other things might be stored in HvAUX later\, too. So\, yes\, it *is* random\, or ought to be considered so\, as any new Perl version could change it.

Do you think we should put all that in the docs? :-)

p5pRT commented 13 years ago

From user42@zip.com.au

"Father Chrysostomos via RT" \perlbug\-followup@&#8203;perl\.org writes​:

:-) OK\, you asked for it​:

Oh dear\, I'm sorry I asked :-).

(It seems iteration has always caused a hash to become defined\, actually.)

Hmm. Not completely outrageous\, I suppose if you could go back in time then perhaps wouldn't have made that so.

Do you think we should put all that in the docs? :-)

Enough to scare away thoughts that it could be close to anything helpful :-)\, then just guidance on what ought to have written ...

(D deprecated) C\<defined()> is usually not right on hashes and has been discouraged since 5.005.

Although C\<defined %hash> has been false on a plain not-yet-used hash\, it becomes true in several non-obvious circumstances\, including iterators\, weak references\, stash names\, even remaining true after C\<undef %hash>. These things make C\<defined %hash> fairly useless in practice.

If a check for non-empty is what you wanted then just put it in boolean context (see L\<perldata/Scalar values>)

  if (%hash) {   # not empty   }

If you had C\<defined %Foo​::Bar​::QUUX> to check whether such a package variable exists then that's never really been reliable\, and isn't a good way to enquire about the features of a package\, or whether it's loaded\, etc.

-- A new life awaits you in the Off-world colonies! A chance to begin again in a golden land of opportunity and adventure!

p5pRT commented 13 years ago

From @cpansprout

On Sat Aug 06 01​:57​:12 2011\, kryde wrote​:

"Father Chrysostomos via RT" \perlbug\-followup@&#8203;perl\.org writes​:

Actually\, it used to return false for a hash that had never had anything in it\, but true for hash that had been empty after having something in it.

That wouldn't be hard to keep\, for compatibility\, would it? Any hv_store() and friends set a flag ...

I forgot to reply to this point. There is no more room for flags. :-(

p5pRT commented 13 years ago

From @cpansprout

On Wed Aug 10 02​:42​:53 2011\, kryde wrote​:

"Father Chrysostomos via RT" \perlbug\-followup@&#8203;perl\.org writes​:

:-) OK\, you asked for it​:

Oh dear\, I'm sorry I asked :-).

(It seems iteration has always caused a hash to become defined\, actually.)

Hmm. Not completely outrageous\, I suppose if you could go back in time then perhaps wouldn't have made that so.

Do you think we should put all that in the docs? :-)

Enough to scare away thoughts that it could be close to anything helpful :-)\, then just guidance on what ought to have written ...

(D deprecated) C\<defined()> is usually not right on hashes and has been discouraged since 5.005.

Not 5.6? I see it in perl56delta (deprecated though\, not discouraged).

Although C\<defined %hash> has been false on a plain not-yet-used hash\, it becomes true in several non-obvious circumstances\, including iterators\, weak references\, stash names\, even remaining true after C\<undef %hash>. These things make C\<defined %hash> fairly useless in practice.

If a check for non-empty is what you wanted then just put it in boolean context (see L\<perldata/Scalar values>)

if \(%hash\) \{
   \# not empty
\}

If you had C\<defined %Foo​::Bar​::QUUX> to check whether such a package variable exists then that's never really been reliable\, and isn't a good way to enquire about the features of a package\, or whether it's loaded\, etc.

p5pRT commented 13 years ago

From @cpansprout

On Wed Aug 10 23​:46​:58 2011\, sprout wrote​:

On Wed Aug 10 02​:42​:53 2011\, kryde wrote​:

"Father Chrysostomos via RT" \perlbug\-followup@&#8203;perl\.org writes​:

:-) OK\, you asked for it​:

Oh dear\, I'm sorry I asked :-).

(It seems iteration has always caused a hash to become defined\, actually.)

Hmm. Not completely outrageous\, I suppose if you could go back in time then perhaps wouldn't have made that so.

Do you think we should put all that in the docs? :-)

Enough to scare away thoughts that it could be close to anything helpful :-)\, then just guidance on what ought to have written ...

(D deprecated) C\<defined()> is usually not right on hashes and has been discouraged since 5.005.

Not 5.6? I see it in perl56delta (deprecated though\, not discouraged).

Digging through history\, I see this in commit 28757baaa (inseparable changes from patch from perl5.003_19 to perl5.003_20)​:

+This counter-intuitive behaviour of defined() on aggregates may be +changed\, fixed\, or broken in a future release of Perl.

p5pRT commented 13 years ago

From user42@zip.com.au

"Father Chrysostomos via RT" \perlbug\-followup@&#8203;perl\.org writes​:

+This counter-intuitive behaviour of defined() on aggregates may be +changed\, fixed\, or broken in a future release of Perl.

Yep. I was looking at perlfunc.pod under defined

  ... On the other hand\, use of defined() upon aggregates (hashes and   arrays) is not guaranteed to produce intuitive results\, and should   probably be avoided.

I spotted it in the 5.005 version\, but I see it's also in 5.004\, so that could be the "discouraged since".

Those words may have been a bit too well hidden to have stopped anyone using it :-)\, esp since "defined %Foo​::BAR" seems a bit natural for asking whether such a variable exists ... (to the novice at least\, what with there not really being a well-defined notion of "exists" for that ...).

-- I bought a packet of baby powder the other day and wasn't happy with it. I went back to the shop and demanded a refund. I told them it obviously wasn't powdered baby\, it was more like talc or something.

p5pRT commented 13 years ago

From @cpansprout

On Fri Aug 12 18​:44​:33 2011\, kryde wrote​:

"Father Chrysostomos via RT" \perlbug\-followup@&#8203;perl\.org writes​:

+This counter-intuitive behaviour of defined() on aggregates may be +changed\, fixed\, or broken in a future release of Perl.

Yep. I was looking at perlfunc.pod under defined

\.\.\. On the other hand\, use of defined\(\) upon aggregates \(hashes and
arrays\) is not guaranteed to produce intuitive results\, and should
probably be avoided\.

I spotted it in the 5.005 version\, but I see it's also in 5.004\, so that could be the "discouraged since".

Iā€™ve just applied your rewording\, with the version number tweaked\, as commit f0ec9725648. Thank you.

Those words may have been a bit too well hidden to have stopped anyone using it :-)\, esp since "defined %Foo​::BAR" seems a bit natural for asking whether such a variable exists ... (to the novice at least\, what with there not really being a well-defined notion of "exists" for that ...).

-- I bought a packet of baby powder the other day and wasn't happy with it. I went back to the shop and demanded a refund. I told them it obviously wasn't powdered baby\, it was more like talc or something.

Try ordering birdseed and an eyedropper.