Re: Logging with Log::StdLog from within a package




Quoth Jerry Krinock <jerry@xxxxxxxx>:
Today, I separated out a file of functions into a separate package:

package MyPackage ;

Instead of 'use', I 'require and call the functions using

MyPackage::aFunction() ;

It works fine except for my Log::Stdlog calls such as:

print {*STDLOG} info => "Hello\n" ;

None of any such calls from inside package functions print to my log
any more. They "just don't work".

Global filehandles are package scoped, so if you opened that STDLOG
filehandle in package main, then you will need

print {*main::STDLOG} info => "Hello\n";

Alternatively, you can 'use Log::StdLog' within your package MyPackage
as well (or instead); this will reopen the logfile but that shouldn't be
a problem.

A confession: I've come a long way with Perl, but one thing still
beyond my comprehension is the 'tie' function with its "enchanted"
variable that seems to be the magic behind {*STDLOG}. What does the
asterisk do?

The {* } is just Damian being paranoid :). Normally that would be
written

print STDLOG info => "Hello\n";

but if you have a sub or a package called STDLOG that statement is
ambiguous, and it's far from obvious how perl resolves that ambiguity.

print {*STDLOG} ...

is just a way of saying 'yes, I really mean the builtin 'print' and the
filehandle 'STDLOG', whatever other ideas you might have'. The fact
STDLOG is tied is not relevant here: you could just as well say

print {*STDERR} ...

if you wanted to.

Ben

--
'Deserve [death]? I daresay he did. Many live that deserve death. And some die
that deserve life. Can you give it to them? Then do not be too eager to deal
out death in judgement. For even the very wise cannot see all ends.'
ben@xxxxxxxxxxxx
.



Relevant Pages

  • Re: Idle thought about bless
    ... an object in the CLASSNAME package." ... All bless does is associate an arbitrary string ... in such a way that the string can be recovered via ref. ... Many live that deserve death. ...
    (comp.lang.perl.misc)
  • Resolving YUM Dependencies
    ... death on my end. ... Can anyone provide some idea of what is causing these ... Package cman-kernel needs kernel = 2.6.12-1.1447_FC4, ...
    (Fedora)
  • package -- what am I doing wrong?
    ... Managing and importing classes is supposed to be easy using PACKAGE. ... public class packageThingie ... I keep getting a message saying the package myPackage ...
    (comp.lang.java.programmer)
  • java package problem
    ... package mypackage; ... javac myapp.java ... I also tried to compile with javac ?cp mypackage\*.class myapp.java ...
    (comp.lang.java.help)
  • Re: Limited Ed. Halo 3 case scratching discs:
    ... three copies both disc were loose inside of the package and scratched ... to death. ... Impossible since the game is not available to the public yet. ...
    (alt.games.video.xbox)