in reply to How best to tell when my hash is "full" (all values defined)?

How 'bout don't pre-create the keys, then just use keys() to count when the number of keys is up to the number you expect?
  • Comment on Re: How best to tell when my hash is "full" (all values defined)?

Replies are listed 'Best First'.
Re^2: How best to tell when my hash is "full" (all values defined)?
by OfficeLinebacker (Chaplain) on Dec 17, 2006 at 04:29 UTC
    D'OH! Thanks!

    I like computer programming because it's like Legos for the mind.
      For that matter, you could just do it like this (adding the suggestion from another reply below):
      my %stats; open(TOP, "top -b -n 1 |"); my $ndone = 0; while (<TOP>) { if ( /up\s.+\s(\d+)\suser.+\s+load\saverage:\s+(\d+\.\d{2}),/ ){ $stats{users}=$1; $stats{load}=$2; $ndone +=2; } elsif ( /(?:Tasks|processes):.+\s+(\d+) running/i ){ $stats{runproc}=$1; $ndone++; } elsif ( /^Mem:\s+(\d+)k\s+(?:total|av),.+used,\s+(\d+)k\s+free/ ){ $stats{tmem}=$1; $stats{fmem}=$2; $ndone += 2; } last if ( $ndone == 5 ); } if ( $ndone < 5 ) { warn "I only got $ndone factoids from top. Bummer.\n"; } else { print "I got everything in just $. lines of input.\n"; }