need help with foreach construct and parsing of list 
Author Message
 need help with foreach construct and parsing of list

Many thanks in advance for your help!  I am a newbie to perl. I am
trying to hack this perl script from HP's website.  I am having a
problem passing the variables and think that my foreach construct and
parsing of the list is incorrect.  I am receiving the following
message when executing the script:

Use of uninitialized value at ./portCheck.pl line 45, <LIST> chunk 11.
Use of uninitialized value at ./portCheck.pl line 45, <LIST> chunk 11.
IO::Socket::INET: Cannot determine remote port at ./portCheck.pl line
45
Use of uninitialized value at ./portCheck.pl line 45, <LIST> chunk 11.
Use of uninitialized value at ./portCheck.pl line 45, <LIST> chunk 11.
Use of uninitialized value at ./portCheck.pl line 45, <LIST> chunk 11.
VPN circuit to ,ip: , port:  may be DOWN!  Please investigate.

My list is a colon delimited file with the following structure:

cus_name:ipaddress:port

Any help is greatly appreciated!

#!/usr/bin/perl -w
############################################################################
## Description:
## o Perl script to check if a particular port on a remote host is
alive...
##   hacked original to accept a list of ip addresses                
         ##   using /foo_bar/vpn_list as input.
##
##   usage:  portCheck.pl <host> <tcp_port>
##                      OR
##           portCheck.pl <enter> (use /usr/local/bin/vpn_list as
input)
############################################################################
Intialize
use strict;
use IO::Socket;

my ( $basedir, $numarg, $ip, $tcpport, $cus_name, $socket );
$basedir="/foo_bar/";

if ($numarg !=2) {
print "Interactive usage:  port_check.pl <host> <tcp_port> OR
port_check.pl <enter> to run against vpn_list\n";
open (LIST, "$basedir/vpn_list") || die "Can't open vpn_list: $!";
while (<LIST>) {
chomp;
foreach my $line (<LIST>) {
  ( $cus_name, $ip, $tcpport) = (split /:/); #split $line, using : as
delimiter

Quote:
}

  }
$ip=$ARGV[0];
$tcpport=$ARGV[1];
$cus_name=$ARGV[2];

#Main
$socket=IO::Socket::INET->new
(
PeerAddr=> "$ip",
PeerPort=> "$tcpport",
Proto=> "tcp",
Type=> SOCK_STREAM
) or die "VPN circuit to $cus_name,ip: $ip, port: $tcpport may be
DOWN!  Please investigate.\n";

print "VPN circuit to $cus_name,ip: $ip, port: $tcpport appears
accessible.\n";

 }
close(LIST);
close($socket);



Sun, 27 Mar 2005 08:54:53 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. Help, I need a case-like construct!

2. help needed with constructing query

3. Please help complete holiday/country list (was: Need list of all legal holidays in all countries)

4. Please help complete holiday/country list (was: Need list of all legal holidays in all countries)

5. Need tcl list parsing in Perl

6. Need help getting out of a foreach loop

7. need help with FOREACH and filename wildcards

8. need help with foreach

9. Constructing a next/more feature for a list display using PERL (CGI)

10. constructing a list of hashes

11. Parsing name list -- Help!

12. help!: RE parse comma separated list

 

 
Powered by phpBB® Forum Software