I'll only provide the methodology that I would use. I won't provide any code, as I don't have the means to test anything right now.

I would first look at your file and look for any patterns. Here's a good start: each server apparently ends with a line starting "AVAILABLE" followed by a blank line then two break lines. You could use these breaklines to split the servers apart from each other. Then you could take the data from each server separately, and skip any breakline or any heading line (the "next if(//)" combo is good in loops for this purpose). Otherwise, each line looks to be a tab separated list. So you can use that to split each line and store the data how you see fit.

As for the TOTAL, USED and AVAILABLE lines, that's something that I would set your loop up to search for. If it sees TOTAL on a line, grab the data associated with it, store it. Same goes for the Used line and the AVAILABLE line.

One caveat. NEVER assume the same number of tabs in a tab separated list (or space separated, etc). Make sure you use the one-or-more flag in your regexp. Otherwise, that first line, which might have two tabs in there, might not parse correctly.

Another Caveat: In some instances, it might be worthwhile to parse the heading lines and grab the headings as your hash keys. First of all, it keeps your data associated with the proper heading. Second of all, I see that on the sis8 server, the heading is different. This would cause problems if you didn't see this up front. You would likely need to nest some of your hashes in order to store the data in a logical way considering there are multiple lines of filesystems for each server.

Hope that helps you think about the world of regexp and data file parsing. It's really a whole different frame of mind.

--Coplan


In reply to Re: couple of file content manipulation questions by Coplan
in thread couple of file content manipulation questions by vxp

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.