in reply to Scalars tied to logfiles

Rather than dieing if unable to open the logfile for writing, I'd just return undef. Of course, I wouldn't use IO::File either, so maybe it's just me.

To figure out where the changes happened to the scalar, have a look at caller

Oh, and you'll probably want to add an UNTIE routine so that users can turn logging on and off without having to wait for object destruction.

Replies are listed 'Best First'.
Re: Re: Scalars tied to logfiles
by mugwumpjism (Hermit) on Dec 11, 2003 at 05:29 UTC

    You don't need to define an UNTIE method for untie($var) to work. If you don't, it just un-sets the flag on the tied scalar, and reduces the reference count on the tie object.

    $h=$ENV{HOME};my@q=split/\n\n/,`cat $h/.quotes`;$s="$h/." ."signature";$t=`cat $s`;print$t,"\n",$q[rand($#q)],"\n";

      Aye, but he'll probably want to close the filehandle on untie.

        Good observation... you made me think it through for a minute.

        I think that because I'm using an object-oriented approach to the file handling (IO::File), when the scalar is either UNTIEd or DESTROYed the IO::File object will have its ref-count dropped down to zero, and the file will be closed automatically.


        Dave