develooper Front page | perl.perl5.porters | Postings from July 2017

keys(%tied_hash) in boolean/scalar context

Thread Next
From:
Dave Mitchell
Date:
July 11, 2017 11:09
Subject:
keys(%tied_hash) in boolean/scalar context
Message ID:
20170711110847.GP3074@iabyn.com
I'm currently working on a branch which improves the handling of various
expressions in boolean context.

One thing I've noticed is the behaviour of keys(%tied_hash) in boolean
and scalar context. It currently iterates over the whole hash, calling
FIRSTKEY() and then NEXTKEY() x n.

I propose that its behaviour be changed.

In boolean context, I would like it to just call SCALAR() if present, or
call FIRSTKEY() just once otherwise,

In scalar context, I would like it to just call SCALAR() if present, or
call FIRSTKEY() and then NEXTKEY() x n otherwise,

This makes (keys %tied_hash) more similar in behaviour to (%tied_hash)
in boolean/scalar context. The only difference now would be that in
non-boolean scalar context, keys(%tied_hash) would call NEXTKEY() x n
whereas (%tied_hash) doesn't.

In summary: for a tied hash %tied_hash

current behaviour:

                       SCALAR() not present     SCALAR() present
                       -------------------      ----------------
    bool:        %h:   FIRSTKEY();              SCALAR();
    scalar:      %h:   FIRSTKEY();              SCALAR();
    bool:   keys %h:   F();N();N();...;         F();N();N();...;
    scalar: keys %h:   F();N();N();...;         F();N();N();...;

proposed behaviour:

                       SCALAR() not present     SCALAR() present
                       -------------------      ----------------
    bool:        %h:   FIRSTKEY();              SCALAR();
    scalar:      %h:   FIRSTKEY();              SCALAR();
    bool:   keys %h:   FIRSTKEY();              SCALAR();
    scalar: keys %h:   F();N();N();...;         SCALAR();

-- 
"But Sidley Park is already a picture, and a most amiable picture too.
The slopes are green and gentle. The trees are companionably grouped at
intervals that show them to advantage. The rill is a serpentine ribbon
unwound from the lake peaceably contained by meadows on which the right
amount of sheep are tastefully arranged." -- Lady Croom, "Arcadia"

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