Of note is that your original code had == '256' comparisons, mixing a numerical operator with a string operand. Why? Either use == 256 (numerically compare against a number) or eq '256' (string comparison against a string). As you really mean the number 256 here, the former is the right choice, even though what you had works too. It does incur a pointless string-to-number conversion, but that's beside the point: you need to be aware of the difference because one day it will bite you if you treat them as interchangeable.#!/usr/bin/perl -w use strict; use Net::SSH qw(ssh); use constant USER => 'root'; use constant CMD => '/usr/local/scripts/temp.sh'; for my $host (qw( 192.168.15.2 192.168.16.2 192.168.17.2 192.168.18.2 )) { (ssh(USER . '@' . $host, CMD) != 256) and last; warn "No response from $host\n"; }
Makeshifts last the longest.
In reply to Re: Not Using So Many 'if' Statements
by Aristotle
in thread Not Using So Many 'if' Statements
by Dru
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |