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

I am attempting to use the Simran::Log::Log and Simran::Error::Error modules, but am running into an interesting problem. The script I am testing with is as follows:
#!/opt/perl5/bin/perl -w use strict; use Simran::Log::Log; use Simran::Error::Error; my $x=5;my $y=4; my $logfile="/home/tstanley/Logfile"; my $syslogger=Simran::Log::Log->new($logfile); my $errlogger=Simran::Error::Error->new(); $errlogger->clear(); if($y<$x){ $errlogger->set("Y is smaller than X"); $syslogger->write("Y is smaller than X"); } my @ERR=$errlogger->msg(); my $ERRMSG=$errlogger->msg(); print "Error is: @ERR\n"; print "Error is: $ERRMSG\n"; my $msg=$syslogger->error(); print "Message is $msg\n";
This generates a “use of an unitialized value in concatenation error” at line 25, which is the last line of the script. This is the snippet from the POD for the Simran::Log::Log module.
Error Description If called in an array context, returns the complete history of err +or messages thus far. Else, returns the latest error message if set. $errmsg = $session->error(); or foreach($session->error()){ print “Error: $_\n”; }
The code for the above subroutine in the Log module is:
sub error { my $self = shift; return $error->msg(); }
where $error is the variable for a Simran::Error::Error object. Now the msg subroutine in the Error module is as follows:
sub msg { my $self = shift; if (wantarray) { return @{$self->{"HISTORY"}}; } return $self->{"ERROR"}; }
Any suggestions as to why I’m banging my head into a wall would be welcomed. I will probably submit a patch to the author of these modules or outright ask if I can take them over (the last update was 26 April 2000, which is also the release date for both of them.)
TStanley
--------
It is God's job to forgive Osama Bin Laden. It is our job to arrange the meeting -- General Norman Schwartzkopf

Replies are listed 'Best First'.
Re: Retrieving Error Messages
by pg (Canon) on Nov 18, 2002 at 18:52 UTC
    The document says that, the error function, if it is used in a scalar context, which is the case you have now, it returns the latest error, if it is set. So it can return undef.

    Just do this:
    print "Message is $msg\n" if $msg;
      Add one point, it should be a universal principle to check undef ALL the time, if you want robust code, not just for this Simran::Log::Log thing.