develooper Front page | perl.perl5.porters | Postings from March 2016

[perl #127788] scalar %hash shows/uses HvTOTALKEYS and notHvUSEDKEYS

Thread Next
From:
yves orton
Date:
March 26, 2016 12:53
Subject:
[perl #127788] scalar %hash shows/uses HvTOTALKEYS and notHvUSEDKEYS
Message ID:
rt-4.0.18-2792-1458996797-1229.127788-75-0@perl.org
# New Ticket Created by  yves orton 
# Please include the string:  [perl #127788]
# in the subject line of all future correspondence about this issue. 
# <URL: https://rt.perl.org/Ticket/Display.html?id=127788 >


HvTOTALKEYS returns the number of keys, including placeholders, in a
hash. HvUSEDKEYS() on the other hand does the right thing. IMO we
should return "0" and "no" for the second then third line of output
below. The "hash in boolean context" internal optimisation does the
right thing, but using the result of scalar(%hash) indirectly does
not.

perl -MHash::Util=lock_keys -le'my %hash=(a=>1); lock_keys(%hash);
delete $hash{a}; print 0+keys %hash; print scalar(%hash); print
0+scalar(%hash) ? "yes" : "no"; print %hash ? "yes" : "no"; print keys
%hash ? "yes" : "no"'
0
1/8
yes
no
no

IMO scalar %hash should return the same thing as 0+keys %hash. But at
the very least these ops should be consistent.

This is a longstanding issue that is present in blead (local patches
are irrelevent):


$ ./perl -v

This is perl 5, version 23, subversion 10 (v5.23.10
(v5.23.9-29-gc94797c*)) built for x86_64-linux
(with 6 registered patches, see perl -V for more detail)

Copyright 1987-2016, Larry Wall

Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5 source kit.

Complete documentation for Perl, including FAQ lists, should be found on
this system using "man perl" or "perldoc perl".  If you have access to the
Internet, point your browser at http://www.perl.org/, the Perl Home Page.

-- 
perl -Mre=debug -e "/just|another|perl|hacker/"


Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About