Re: Logging with Log::StdLog from within a package
- From: Ben Morrow <ben@xxxxxxxxxxxx>
- Date: Thu, 31 Jul 2008 15:06:54 +0100
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
.
- Follow-Ups:
- Re: Logging with Log::StdLog from within a package
- From: Jerry Krinock
- Re: Logging with Log::StdLog from within a package
- References:
- Logging with Log::StdLog from within a package
- From: Jerry Krinock
- Logging with Log::StdLog from within a package
- Prev by Date: FAQ 3.24 Why don't Perl one-liners work on my DOS/Mac/VMS system?
- Next by Date: Re: Extracting bits out of huge numbers
- Previous by thread: Logging with Log::StdLog from within a package
- Next by thread: Re: Logging with Log::StdLog from within a package
- Index(es):
Relevant Pages
|