Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re^7: If conditional checks

by Kenosis (Priest)
on Dec 13, 2012 at 00:48 UTC ( #1008614=note: print w/ replies, xml ) Need Help??


in reply to Re^6: If conditional checks
in thread If conditional checks

Ah! We just need to do something a little different with the partial match:

#!/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.


Comment on Re^7: If conditional checks
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1008614]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (8)
As of 2014-11-26 17:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (172 votes), past polls