Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re^2: parsing system info

by Narveson (Chaplain)
on May 27, 2008 at 17:22 UTC ( #688704=note: print w/replies, xml ) Need Help??


in reply to Re: parsing system info
in thread parsing system info

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; }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://688704]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (5)
As of 2021-10-26 21:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My first memorable Perl project was:







    Results (91 votes). Check out past polls.

    Notices?