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); } }
In reply to Lammentful logs fouled by failing filehandling by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |