> -----Original Message-----
> From: Troy Denkinger [mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, August 14, 2001 9:58 AM
> To: John Sands; [EMAIL PROTECTED]
> Subject: Re: how many items in a hash?
> 
> 
> On Tuesday 14 August 2001 10:36, John Sands wrote:
> > Is there a simple way to know whether a hash has items in 
> it? Like using
> > @ARRAY in a scalar context gives the size of an array. Or 
> using $#ARRAY
> > gives the last valid index.
> 
> Calling keys() on the hash will return a list of the keys in 
> the hash.  
> Calling scalar() on that list will give you the number of 
> elements in the 
> list.

Or, from perldoc perldata:

      If you evaluate a hash in scalar context, it returns false if the hash
      is empty.  If there are any key/value pairs, it returns true; more
      precisely, the value returned is a string consisting of the number of
      used buckets and the number of allocated buckets, separated by a
      slash.

print "Empty!\n" unless %myhash;

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to