#!/usr/local/bin/perl
use strict;
use warnings;
use List::Util qw/sum/;
my $host = 'db201.tp.mud';
my @redAlert = ("db");
my @orangeAlert = ( "c", "sm" );
my %status =
( 'status_history' => { 'status' => [ 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 ]
+ } );
my $statusHist01 = sum @{ $status{status_history}{status} }[ 0 .. 1 ]
+;
my $statusHistTot = sum @{ $status{status_history}{status} };
if (
grep $host =~ /^$_/i, @redAlert
or ( grep $host =~ /^$_/i, @orangeAlert and $statusHist01 == 2 )
or $statusHistTot == 3
)
{
print "We've got a winner!";
}
The earlier grep worked because we were looking for an exact match. In this case, however, we want a partial match of the alert elements with the host. Also, since the alerts don't contain any 'special' characters, escaping isn't necessary. |