Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
I am pretty new to programming. I do my best to live by the docs, but sometimes strange things get me. I have tried several variations of this code. It logs it correctly (as I expect it to), but it also sets $! to 'Inappropriate I/O control operation.'
Oh, teachers of perl wisdom, where have I failed my poor program?
logger('I would like to log an arbitrary string, please.');sub logger{ my $entry = shift(@_); my $logpath = 'C:\\Logs\\MailServer\\'; use vars qw($sec $min $hour $mday $mon $year $wday $yday $isdst); ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime( +time); my $datestamp = (1900+$year).'_'.(1+$mon).'_'.$mday; my $timestamp = '~<'.$hour.':'.$min.':'.$sec.'>~ '; my $logname = $logpath.$datestamp.'.log'; if ($entry){ open my $LOG, ">>", "$logname" or die $!; print $LOG "$timestamp$entry\n"; say $timestamp.$entry; close($LOG); } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Lammentful logs fouled by failing filehandling
by JavaFan (Canon) on Apr 30, 2012 at 22:15 UTC | |
|
Re: Lammentful logs fouled by failing filehandling
by eyepopslikeamosquito (Archbishop) on May 01, 2012 at 10:09 UTC | |
by shain (Initiate) on May 01, 2012 at 15:10 UTC |