Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: How should I understand scalar(%hash) results?

by BrowserUk (Patriarch)
on Oct 05, 2004 at 08:45 UTC ( [id://396520]=note: print w/replies, xml ) Need Help??


in reply to How should I understand scalar(%hash) results?

Good guess :) From perldata:

..., but evaluating %HASH in scalar context reveals "1/16", which means only one out of sixteen buckets has been touched, ...

Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"Think for yourself!" - Abigail
"Memory, processor, disk in that order on the hardware side. Algorithm, algorithm, algorithm on the code side." - tachyon
  • Comment on Re: How should I understand scalar(%hash) results?

Replies are listed 'Best First'.
Re^2: How should I understand scalar(%hash) results?
by TVSET (Chaplain) on Oct 05, 2004 at 08:47 UTC
      In normal programs the only interesting thing about this is that it's guaranteed to return false for an empty hash and something that's true otherwise. So you can check if a hash is empty or not by simply using the hash name in boolean context (which is a scalar context):
      if (%hash) { ..do something for a filled %hash... } else { ...do something for an empty %hash... }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://396520]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (4)
As of 2024-09-20 07:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    The PerlMonks site front end has:





    Results (25 votes). Check out past polls.

    Notices?
    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.