[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Omaha.pm] AI-type string comparisons using Perl...
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hello everyone!
I am working on a small script that will compare some text output from a
program and parse out the numbers I want to act upon. Unfortunatly the
output from the script is quite "humanized" and really ugly to parse
using RegExp.
Does anyone know of a perl module/function that can take a template
string and use that to extract the values into variables for further
use?
Here is how I am starting to work on this:
1 @OUTPUT = `/path/to/ovstatus`;
2 #--begin output---
3 # object manager name: netmon
4 #...snip...
5 # 14:30:00 Polling 0 interfaces, 0 polls/hour. 0 overdue polls,
current maximum 0 [...etc...] average 0.2 msec/lookup.
6 #--end output---
7 ($LINE) = grep /overdue.polls/i, @OUTPUT;
8 $RAWRATE =~ /Polling.*, (\d*) ([^\s]*)\. /i;
9 $RATE = $1;
10 $RATEUNITS = $2;
...and so on...
Line 7 finds the single line that I want to work with and puts that into
$LINE.
I have to repeat lines 8-10 for all the values I want to pull out of that
line. I started with a single large regexp that was a nightmare to debug
if I got off in my RegExp syntax. :(
Anyone got other ideas? I will be using this method for many other
programs on the system I want to monitor so the more flexible the parsing
routine the better.
Dan
- - - - -
"I do not fear computer,
I fear the lack of them."
-- Isaac Asimov
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)
iD8DBQFBG4jcNiBNyqUzGb8RAlE9AJwO6dFCgsPy4lfIhYvAtER2DcI/SACZAf5R
RU8GrLUCrHhchmF53ASntm0=
=EJd3
-----END PGP SIGNATURE-----