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

D'OH! Thanks!

I like computer programming because it's like Legos for the mind.
  • Comment on Re^2: How best to tell when my hash is "full" (all values defined)?

Replies are listed 'Best First'.
Re^3: How best to tell when my hash is "full" (all values defined)?
by graff (Chancellor) on Dec 17, 2006 at 06:37 UTC
    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"; }