I am curious about a value in $! (that is suppose to represent an error?) even though my script works fine. I am still working on my first script so please be gentle.
The script I'm working on reads an access log and searches for certain strings in it (which represent UserID's of Participants and Observers). The script works fine but sometimes there's a disk read error in the access.log file and the script fails. I wanted to update the script so in case of a disk read error it will return some error code.
After searching for info for a while I found this: http://perldoc.perl.org/functions/readline.html where they recommend a way to check for errors while reading a line from a file:
Since they begin with undef $! I though I will check to see what is the value of $! before I "undef" it. I found that after $line=<IN>; it holds "Bad file descriptor". Again, my script works fine.1. for (;;) { 2. undef $!; 3. unless (defined( $line = <> )) { 4. last if eof; 5. die $! if $!; 6. } 7. # ... 8. }
Here is the beginning of my script:
The first time I print $! , there's nothing in it, the second time, after $line=<IN>, it holds "Bad file descriptor".#!/usr/bin/perl -w use strict; my $SessionID = $ARGV[0]; # my $infile="\\\\10.0.16.97\\c\$\\web\\Apache-SSL\\logs\\access.log"; my $infile="Input\\access.log"; my $outfile="Output\\$SessionID\.html"; my $plogfile="Output\\$SessionID\-participants-log.html"; my $ologfile="Output\\$SessionID\-observers-log\.html"; my $line; my ($logtime,$starttime,$endtime,$timecheck); my ($FullURL,$ObURL); my ($UserID,$ObserverID); my (@Participants,@Observers); sub TranslateURL; # Changes all URL Escape Codes to regular charecters sub GetUserID; # Gets UserID from FullURL sub GetObserverID; # Gets ObserverID from ObURL sub AddToUserArray; # Checks if this is a new user and adds to user ar +ray sub AddToObserverArray; # Checks if this is a new observer and adds to + observer array sub AddToUserLog; # Adds a line to the user log with the userid, URL a +nd time. sub AddToObserverLog; # Adds a line to the observer log with the obser +verid, URL and time. sub ShowupSummary; #################### #Beginning of script #################### $starttime=localtime(); print "Script starting at $starttime\n"; open(IN,"<","$infile") || die "Can't open input file $infile"; $timecheck=localtime(); print "Finished open log file at $timecheck\n"; open(PLOG,">","$plogfile") || die "Can't open participants log file $p +logfile"; print PLOG "\<html\>\n\<head\>\n\<STYLE TYPE\=\"text\/css\"\>\n\<\!\-\ +-\nTD\{text\-align\: center\; font\-family\: Arial\; color\: \#FFFFFF +\; font\-size\: 10pt\;\}\nTH\{font\-family\: Arial\; font\-size\: 10p +t\; background\-color\: \#99CCFF\;\}\n\-\-\-\>\n\<\/STYLE\>\n\<\/head +\>\<body\>\n\<center\>\<font face\=Arial\>\n\<table background\=\"ima +ges\/bluegradient\.jpg\" border\=1 cellspacing\=0 cellpadding\=5\>\<t +r\>\n\<th\>User ID\<\/th\>\n\<th\>URL\<\/th\>\n\<th\>Time\<\/th\>\n\< +\/tr\>\n"; close PLOG; open(OLOG,">","$ologfile") || die "Can't open file $ologfile"; print OLOG "\<html\>\n\<head\>\n\<STYLE TYPE\=\"text\/css\"\>\n\<\!\-\ +-\nTD\{text\-align\: center\; font\-family\: Arial\; color\: \#FFFFFF +\; font\-size\: 10pt\;\}\nTH\{font\-family\: Arial\; font\-size\: 10p +t\; background\-color\: \#99CCFF\;\}\n\-\-\-\>\n\<\/STYLE\>\n\<\/head +\>\<body\>\n\<center\>\<font face\=Arial\>\n\<table background\=\"ima +ges\/bluegradient\.jpg\" border\=1 cellspacing\=0 cellpadding\=5\>\<t +r\>\n\<th\>User ID\<\/th\>\n\<th\>Time\<\/th\>\n\<\/tr\>\n"; close OLOG; open(OUT,">","$outfile") || die "Can't open file $outfile"; print OUT "\<html\>\n\<head\>\n\<STYLE TYPE\=\"text\/css\"\>\n\<\!\-\- +\nTD\{text\-align\: center\; font\-family\: Arial\; color\: \#FFFFFF\ +;\}\nTH\{font\-family\: Arial\; color\: \#FFFFFF\;\}\n\-\-\-\>\n\<\/S +TYLE\>\n\<\/head\>\<body\>\n\<center\>\<font face\=Arial\>\n\<table b +ackground\=\"images\/bluegradient\.jpg\" border\=1 cellspacing\=0 cel +lpadding\=5\>\<tr\>\n\<th\>No data to display yet\<\/th\>\n\<\/tr\>\n +"; close OUT; print "$!\n"; system('pause'); $line=<IN>; print "$!\n"; system('pause'); while ($line) { #Rest of script...
Can someone please explain to me why this "error" appears? If my script works fine, should I be worried?
Thank you for your patience!
okarmiIn reply to Bad file descriptor by okarmi
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |