Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

scalar %hash shows/uses HvTOTALKEYS and not HvUSEDKEYS #15252

Open
p5pRT opened this issue Mar 26, 2016 · 4 comments
Open

scalar %hash shows/uses HvTOTALKEYS and not HvUSEDKEYS #15252

p5pRT opened this issue Mar 26, 2016 · 4 comments

Comments

@p5pRT
Copy link

p5pRT commented Mar 26, 2016

Migrated from rt.perl.org#127788 (status was 'open')

Searchable as RT127788$

@p5pRT
Copy link
Author

p5pRT commented Mar 26, 2016

From @demerphq

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/"

@p5pRT
Copy link
Author

p5pRT commented Mar 26, 2016

From @demerphq

Note that the ticket here is slightly inaccurate. When HvTOTALKEYS is

1 it shows the result of HvFILL, which does not respect placeholders
and is non-deterministic under hash randomization.

We should show HvUSEDKEYS() instead.

On 26 March 2016 at 13​:53, yves orton <perlbug-followup@​perl.org> wrote​:

# 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-archive.perl.org/perl5/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/"

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

@p5pRT
Copy link
Author

p5pRT commented Mar 26, 2016

From @mauke

Am 26.03.2016 um 13​:53 schrieb yves orton (via RT)​:

IMO scalar %hash should return the same thing as 0+keys %hash.

+1

--
Lukas Mai <plokinom@​gmail.com>

@p5pRT
Copy link
Author

p5pRT commented Mar 26, 2016

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants