#!/usr/bin/perl
use strict;
use warnings;
use Benchmark qw(:all);
cmpthese(-1, {
'Fishmonger' => \&Fishmonger,
'Bill' => \&Bill,
'Saurabh' => \&Saurabh,
});
sub Fishmonger {
my %service;
open my $dat_fh, '<', 'status.dat' or die "failed to open 'status.dat <$!>\n";
while ( my $line = <$dat_fh> ) {
if ( $line =~ /^service {/ .. $line =~ /^}/ ) {
next if $line =~ /^(service {|})/;
chomp $line;
my ($key, $value) = split /=/, $line;
$service{$key} = $value;
}
}
close $dat_fh;
}
sub Bill {
my %hash;
open my $dat_fh, '<', 'status.dat' or die "failed to open 'status.dat <$!>\n";
while ( <$dat_fh> ) {
chomp;
next if ( !/(:?host_name|current_state|notifications_enabled)/ );
%hash = ( %hash, split /=/ );
}
close $dat_fh;
}
sub Saurabh {
my @array=("host_name","current_state","notifications_enabled");
my %hash;
for $_ (@array) {
my $keyname=`grep "$_" status.dat`;
my $val=substr(substr($keyname,rindex($keyname,'=')),1);
if(($keyname ne "") && ($val ne "")) {
chomp($val);
$hash{$_}=$val;
}
}
}