tc1364 has asked for the wisdom of the Perl Monks concerning the following question:

Can you please help me with the print LOG statement because it doesn't work here for some reason? All of the rest of the code works great.
$workbook->close() or die "LOG->Error Closing File: $!"; $time = localtime(); print LOG "$time Completed West XLS Generation\n"; close(LOG); exit 0;

Replies are listed 'Best First'.
Re: Filehandler Trouble
by samtregar (Abbot) on Dec 14, 2004 at 19:40 UTC
    Can you please explain what you mean by "doesn't work"? Are you getting an error message? Maybe you should check the return value from print() and close(). Also, can you show us the open() call for LOG?

    -sam

      Sorry about getting back so late it is getting busier over here. The message doesn't get printed into the eadas.log file by the filehandler LOG. This was puzzling me because my other messages are being printed into the eadas.log file by the filehandler OK. There are no error messages being reported. What would be the best way to check the return values for the calls you mention and so that they can be checked?
      open(LOG, ">> $log/eadas.log") or die "Can't open $log/eadas.log: $!\n +"; LOG->autoflush(1);
        Try this:

        print LOG "foo" or die "Unable to print: $!"; close LOG or die "Unable to close: $!";

        -sam

        The code was changed to die if there was any trouble with closing or printing to the LOG filehandler and the code never reported any errors but "foo" was never printed into log file by the filehandler.
Re: Filehandler Trouble
by yacoubean (Scribe) on Dec 14, 2004 at 20:08 UTC
    I'm not sure if 'LOG' is a perl expression I'm not aware of or something, but if not, shouldn't it be:
    print $LOG "$time Completed West XLS Generation\n";
    Update: Ignore the jester in the corner...

      Presumably it's the name of a global filehandle, as in:

      open LOG, '>', $filename or die "Can't open '$filename': $!\n";
        I found where the trouble is please see the below code.
        $workbook->close() or die "LOG->Error Closing File: $!";
        The code was changed to the below.
        $workbook->close() or die "Error Closing File: $!";
        Can you please explain what is wrong with the original syntax?