Hello monks, I'm running into something that is confusing me quite a bit. I've borrowed a nice little logging class, er, package written by Jeff Rowan from: http://jrf.odpn.net/writings/Log.pm I seem to recall it was working fine for a short time (I got logs anyway, and still do actually), and after a number of modifications to my program it seems to have started complaining (maybe it always complained and the way I was starting my program masked that). I'm now getting a somewhat cryptic (to me) error which seems to indicate I'm not passing enough information to the object when it is constructed, but I don't see what could be missing or why. I'm creating a new log object:
my $log = new File::QuickLog(file => "logtaild.log");
And then using the print method like so:
$log->print("Starting in build mode.");
The error I'm getting is this:
(in cleanup) Can't call method "open" on an undefined value at ./logt +aild.pl line 334 during global destruction.
So I think what is happening is that the $log object no longer (or ever) had some piece of information needed for the open...that seems to make sense, except the information needed should all be there as far as I can tell:
my $self = bless { _logfile => $arg{'file'} ? $arg{'file'} : $arg[0], _fh => new FileHandle, _logstart => _datetime(), }, $class;
From this I'm thinking we've got _logfile from 'file' during construction, and _fh comes from the Filehandle object, and logstart is just a timestamp created by a small date object included in the log class.

The line that is complaining is here:

unless($self->{'_fh'}->open (">>".$self->{'_logfile'})){ croak "Failed to open \"".$self->{'_logfile'}."\""; }
It looks like we're calling open with the filehandle object that we constructed earlier, and the logfile name that was passed to the object constructor.

The object language/syntax of perl still baffles me, so I suspect my problems are more opaque to me than to someone who understands objects in perl better. If larger code snippets are required, let me know--the full module is linked above, and it is quite simple to understand (even for me, except for some of the object stuff).

Anyway, thanks for any pointers anyone can provide that will set me on the path. I'm running with Use strict and -w, of course...


In reply to Objects and undefined values by SwellJoe

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.