I have the following partially written script:
I am getting 3 errors when I run this:
Use of uninitialized value in print at /usr/local/bin/fixawconf.pl line 19, <FHIN> line 1.
Use of uninitialized value in index at /usr/local/bin/fixawconf.pl line 20, <FHIN> line 1.
Write error: Bad file descriptor at /usr/local/bin/fixawconf.pl line 23, <FHIN> line 1.
It seems that it doesn't like something about my file descriptor (FHIN) although it is '$line' that is the common element in the lines the error is complaining about. Can someone tell me what I am doing wrong? TIA.
Code:
#!/usr/bin/perl -w
#
# This script fixes the AWStats config file so the current IP address is
# included in the statistics
#
use strict;
my $awcfgfile = "awstats.conf";
my $awcfgdir = "/etc/awstats";
my $tmpcfgfile = "awstatsnew.conf";
open(FHIN,"< $awcfgdir/$awcfgfile") || die "Unable to open $awcfgfile for input:
$!\n";
open(FHOUT,"> /tmp/$tmpcfgfile") || die "Unable to open /tmp/$tmpcfgfile for out
put: $!\n";
my $line="";
my $indx=0;
while (! undef ($line=readline(FHIN))) {
print $line;
if (($indx=index($line,"HostAliases"))>=0) {
print "Found it!\n";
}
print FHOUT $line || die "Write error: $!";
}
close(FHOUT);
close(FHIN);
Use of uninitialized value in print at /usr/local/bin/fixawconf.pl line 19, <FHIN> line 1.
Use of uninitialized value in index at /usr/local/bin/fixawconf.pl line 20, <FHIN> line 1.
Write error: Bad file descriptor at /usr/local/bin/fixawconf.pl line 23, <FHIN> line 1.
It seems that it doesn't like something about my file descriptor (FHIN) although it is '$line' that is the common element in the lines the error is complaining about. Can someone tell me what I am doing wrong? TIA.