Little utilities each parsing one set of information is how the "tools" do it, but that doesn't help me learn more about parsing larger things such as this.

I'd say develop little utilities each parsing one set of information.

You are planning a big utility that opens your data file once and reads everything. Instead, let each little utility open the file, scan through for what it needs, and ignore everything it doesn't know about. That way you can build and test one little piece at a time.

After you've written several little utilities, you'll find they all use some of the same tricks, e.g. the regex for reading the server name. You will want to put these repeated snippets into a module that each little utility can use. Do that module later. Start by building some little thing that works right now.

For example, the df request returns a table with column headings. Have a little utility that handles this.

# regexes referenced below should be defined or imported here # hash of hashes summarizing df results my %partitions_on; LINE: while (<>) { # pull the server name from a line like [jboss-box1] my ( $server ) = /$SERVER_PATTERN/; next LINE if !$server; # skip what doesn't relate to the df command NON_DF_INFO: while (<>) { last NON_DF_INFO if /$DF_PATTERN/; } my $header = <>; my @cols = split; my %value_of; DATA: while (<>) { last DATA if /$BLANK/; @value_of{@cols} = split; } %partitions_on{$server} = \%value_of; # go back to hunting for another server next LINE; }

In reply to Re^2: parsing system info by Narveson
in thread parsing system info by 5mi11er

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.