Hi again :) The following code (I plan to implement the piped open shortly, but just used what I have to test the memory usage of the hashes in the two approaches)
my @raw=`top -b -n 1`; my (%stats,%stats2); my $expected_keys = 5; @stats{'users','load','tmem','fmem','runproc'} = (); my $its=0; foreach my $line (@raw){ if ($line =~ /up\s.+\s(\d+)\suser.+\s+load\saverage:\s+(\d+\.\d{2}), +/){ $stats{users}=$1; $stats{load}=$2; $stats2{users}=$1; $stats2{load}=$2; } elsif ($line =~ /(?:Tasks|processes):.+\s+(\d+) running/i){ $stats{runproc}=$1; $stats2{runproc}=$1; } elsif ($line =~ /^Mem:\s+(\d+)k\s+(?:total|av),.+used,\s+(\d+)k\s+fr +ee/){ $stats{tmem}=$1; $stats{fmem}=$2; $stats2{tmem}=$1; $stats2{fmem}=$2; } $its++; print scalar(%stats2); print scalar(%stats); (scalar(keys(%stats2)) == $expected_keys) && last; } ## end foreach my $line (@raw)
outputs

2/8
4/8
2/8
4/8
2/8
4/8
4/8
4/8
So the memory usage is no different (correct me if I am wrong--my understanding is that the number we are worried about (if we're worried about memory consumption) is the divisor).

I'll go ahead and make the call to `top` a piped open and have done with it. Thanks for your help (everyone who posted).

T.

I like computer programming because it's like Legos for the mind.

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.