Front page | perl.beginners |
Postings from February 2012
Re: Parsing Question
Thread Previous
From:
Igor Dovgiy
Date:
February 1, 2012 08:38
Subject:
Re: Parsing Question
Message ID:
CADGQiHGvZAU+12SrJONcYBevNPa7ciAHwm901HeFuzB1r9o_5w@mail.gmail.com
Just my $0.02... can't help offering a slight rewrite of David's great
program.
Now it's runnable on 5.010 and earlier, and should give out some warnings
if hoststatus sections are somehow corrupt:
$|++; # comment it out if you don't need to buffer the output
my $section_started;
my ($host, $state);
while(<DATA>) {
if ($section_started) {
$host = $1, next if /host_name=(\w+)/;
$state = $1, next if /current_state=(\d+)/;
if (/^\s*}\s*$/) {
print defined $host && defined $state
? "$host:$state\n"
: "Invalid section started at $section_started\n";
$section_started = 0;
}
}
else {
$section_started = $., ($host, $state) = () if /hoststatus\s*{/;
}
}
-- iD
2012/2/1 Brandon Phelps <bphelps@gls.com>
> Thanks a ton David,
>
> This will definitely help! Not able to try it now but I'll give it a shot
> first thing tomorrow.
>
> -Brandon
>
> --
> To unsubscribe, e-mail: beginners-unsubscribe@perl.org
> For additional commands, e-mail: beginners-help@perl.org
> http://learn.perl.org/
>
>
>
Thread Previous