perl return ips after successful ping

Hi,

I have this script in ksh, what it does is loop every ip in the nodes_nso and produced another variable up_nodes_nso of only ip's that are up.

nodes_nso=$(cat /var/tmp/nodes.txt)

echo "ICMP Tests:"
up_nodes_nso=""
for ip in ${nodes_nso} ; do
  ping ${ip} 3 > /dev/null
  if [ "${?}" -eq "0" ]; then
    status="OK"
    up_nodes_nso="${up_nodes_nso} ${ip}"
  else
    status="DOWN"
  fi
  echo "NSO Node ${ip}: ${status}"
done

I want to convert this script to perl, is there an easy way to do this

There's no magical ksh2perl conversion program or method. It'll need just plain rewriting.

Why perl, though? It's such a pig of a language for such a tiny simple task, and this'd be easy enough to convert to plain sh. (There are other potential improvements, as well.) Isn't there any shell on the system?

Also, what version of ping are you using? Mine can't take an option '3' like that.

---------- Post updated at 10:12 AM ---------- Previous update was at 10:06 AM ----------

#!/usr/bin/perl

my $ip;
my @up;

open(IN1,"</tmp/nodes.txt");

while($ip=<IN1>)
{
        chomp($ip);
        if($ip != "")
        {
                $ret=system("ping -c 3 $ip > /dev/null");
                if($ret == 0)
                {       push @up, $ip;          }
        }
}

exit 0;