diff options
author | Ricardo Signes <rjbs@semiotic.systems> | 2020-09-06 20:29:53 -0400 |
---|---|---|
committer | Karl Williamson <khw@cpan.org> | 2020-09-06 20:47:53 -0600 |
commit | 6e30921bebdc2219286b39c1c0468b7d16aed772 (patch) | |
tree | ce71422425467fc029841654e04db8ed8504e36d /pod/perldsc.pod | |
parent | 8084d6ce801351667ed6895bd95ad6c288479375 (diff) | |
download | perl-6e30921bebdc2219286b39c1c0468b7d16aed772.tar.gz |
perldsc: eliminate unnecessary call to keys()
A hash in scalar context now evalutes to its key count, meaning that
(%h1 <=> %h2) is equivalent to, but shorter than, (keys %h1 <=> keys
%h2). I have dropped calls to keys() in this code to make it clearer.
(This commit may be controversial, as in some places scalar(@arr) is
being used with the suggestion that it provides values.)
Diffstat (limited to 'pod/perldsc.pod')
-rw-r--r-- | pod/perldsc.pod | 8 |
1 files changed, 2 insertions, 6 deletions
diff --git a/pod/perldsc.pod b/pod/perldsc.pod index f6aae40ebb..50cc0683e8 100644 --- a/pod/perldsc.pod +++ b/pod/perldsc.pod @@ -666,9 +666,7 @@ X<hash of hashes> X<HoH> # print the whole thing sorted by number of members - foreach $family ( sort { keys %{$HoH{$b}} <=> keys %{$HoH{$a}} } - keys %HoH ) - { + foreach $family ( sort { $HoH{$b}->%* <=> $HoH{$a}->%* } keys %HoH ) { print "$family: { "; for $role ( sort keys $HoH{$family}->%* ) { print "$role=$HoH{$family}{$role} "; @@ -681,9 +679,7 @@ X<hash of hashes> X<HoH> for ( qw(lead wife son daughter pal pet) ) { $rank{$_} = ++$i } # now print the whole thing sorted by number of members - foreach $family ( sort { keys %{ $HoH{$b} } <=> keys %{ $HoH{$a} } } - keys %HoH ) - { + foreach $family ( sort { $HoH{$b}->%* <=> $HoH{$a}->%* } keys %HoH ) { print "$family: { "; # and print these according to rank order for $role ( sort { $rank{$a} <=> $rank{$b} } |