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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |