in reply to If conditional checks
Here's one way to do it, using the same logic you've used:
use strict; use warnings; use List::Util qw/sum/; my $host = 'db'; 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 ( $host ~~ @redAlert or ( $host ~~ @orangeAlert and $statusHist01 == 2 ) or $statusHistTot == 3 ) { print "We've got a winner!"; }
The alerts are contained in arrays, so Perl's (v5.10+) smart operator (~~) can be used to check whether the value of $host is an element of either array. List::Util's sum is used to sum the relevant values from the status list.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: If conditional checks
by kitkit201 (Initiate) on Dec 09, 2012 at 05:14 UTC | |
by tobyink (Canon) on Dec 09, 2012 at 11:06 UTC | |
by Kenosis (Priest) on Dec 09, 2012 at 05:45 UTC | |
by kitkit201 (Initiate) on Dec 12, 2012 at 20:13 UTC | |
by Kenosis (Priest) on Dec 12, 2012 at 21:46 UTC | |
by kitkit201 (Initiate) on Dec 13, 2012 at 00:16 UTC | |
|