Im getting a 'Use of uninitialized value in concatenation (.) or string at ./working.pl line 95, <CONFIGFILE> line 5.' from the following code. I thought at first it might be the \n at the end of the print statement at the end, I removed it and still get the warning. Can anyone point me in the right direction? Ill post the config file Im using for testing at the end also.
thanks
#!/usr/bin/perl # mothership.pl # Ted Fiedler (tfiedler@gmail.com) # See NOTES for more info use strict; use warnings; use IO::Socket::INET; # does network socket connections # use POSIX qw(strftime); # time # use File::Copy; # file copy operations # use Data::Dumper; # for testing # ################################################### # User configurable variables # ################################################### my $path_to_ship = "/home/tfiedler/network"; my $configfile = "mothership.cfg"; ################################################### # configuration file is here # ################################################### open( CONFIGFILE, "$path_to_ship/$configfile" ) || die "$!\n"; my @information = <CONFIGFILE>; # pull config into array ################################################### # This file will hold _new_ status # ################################################### open( NEWSTATS, "> status.new" ) || die "$!\n"; ################################################### # Copy _previous_ stats to _old_ stats file # # for comparison # ################################################### my $copystats = ( -e "status.msp" ) ? copy( "status.msp", "status.old" ) : warn "Unable to copy status.msp to status.old $!\n"; ################################################### # iterate through each line in config and do # # processing here. # ################################################### foreach $_ (@information) { chomp($_); # break each line into individual vars # my ( $hostname, $ipadd, $port, $proto, $description ) = split( /,/ +, $_ ); # create a hash services with key hostname and values # # $ipadd => ipaddress, $port => port number, $proto => protocol # my %services = ( $hostname => [ $ipadd, $port, $proto ] ); my %status; # initially everything is up # $status{$_} = 'Up' for keys %services; while ( my ( $name, $svc ) = each %services ) { my $sock = IO::Socket::INET->new( Timeout => 2, PeerAddr => $svc->[0], PeerPort => $svc->[1], Proto => $svc->[2] ) # or else it is down # or $status{$name} = 'Down'; } # end of while statement # # This will be changed to reflect a correct last up and down times + # # eventually for comparison and evaluation of total uptime + # # my $nowstring = strftime '%F %R', localtime; # my $oldtime; # for future use # my $nowstring = time; # in seconds # # this next line is EACH name (aka host) and its corresponding sta +tus # while ( my ( $name, $sts ) = each %status ) { # find out what nervice this is # # man getservbyport for more info # my $svcwatch = ( $name !~ /^#/ ) ? getservbyport( $port, $proto ) : next; ################################################### # pick through the data and skip anything that # # doesnt qualify # ################################################### next unless ($hostname); next unless ( $ipadd =~ /^(\d+)\.(\d+)\.(\d+)\.(\d+)$/ ); next unless ( $port =~ /^(\d+)/ ); next unless ( $proto eq "udp" || $proto eq "tcp" || $proto eq +"icmp" ); unless ( $description =~ m/\w/ ) { $description = "No Description entered"; } # end of unless # # print out the data to status.new # # this will eventually get changed to status.msp for now # # I use status.new for testing # print NEWSTATS "$name,$sts,$svcwatch,$description,$nowstring\n +"; print Dumper "$name,$sts,$svcwatch,$description,$nowstring\n"; } # End of while ( my ($name, $sts ... ) } # end of toplevel ( 1st foreach ) close(NEWSTATS); # copy status.new to status.msp # copy( "status.new", "status.msp" ) || die "Unable to copy status.new to status.msp\n"; # EOF #
and the config file
#Server name, IP Address, port number, protocol (tcp/udp), description + (optional) linux,127.0.0.1,22,tcp, linux,127.0.0.1,8080,tcp,Local web server linux,127.0.0.1,22,udp,Local SSH using udp linux,127.0.0.1,504,tcp,Citadel server on local

Readmore tags added by davido per consideration.


In reply to Use of uninitialized value warning on print by tcf03

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.