Skip Menu |

This queue is for tickets about the Log-StdLog CPAN distribution.

Report information
The Basics
Id: 21235
Status: open
Priority: 0/
Queue: Log-StdLog

People
Owner: Nobody in particular
Requestors: cht [...] cvt.dk
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: Bug with Log::StdLog v. 0.0.3
Date: Wed, 30 Aug 2006 14:49:13 +0200
To: bug-log-stdlog [...] rt.cpan.org
From: Christian Tønsberg <cht [...] cvt.dk>
Hi, Thank you for (yet another) useful module! I belive I have discovered a bug. It can be demonstrated by the following commandline invocations of perl: $ perl -e' use Log::StdLog { file=>"foo" }; print {*STDLOG} error=>"bar";' $ perl -e'my $f="foo"; use Log::StdLog { file=>"$f" }; print {*STDLOG} error=>"bar";' $ perl -e'my $f="foo"; use Log::StdLog { file=>$f }; print {*STDLOG} error=>"bar";' The first works fine. The second makes Log::StdLog report Unable to open log file '' at -e line 1 The third makes Log::StdLog report Use of uninitialized value in open at /usr/local/share/perl/5.8.4/Log/StdLog.pm line 90. Use of uninitialized value in concatenation (.) or string at /usr/local/share/perl/5.8.4/Log/StdLog.pm line 90. Unable to open log file '' at -e line 1 I cannot find anything in the documentation for Log::StdLog that lead me to belive that filenames cannot be passed as in the second and third example above. I hope this can be resolved. Thanks in advance. Cheers, Christian -- Christian Tønsberg, M.Sc. Technical Project Coordinator Technical Knowledge Center of Denmark (http://www.dtv.dk/) Technical University of Denmark (http://www.dtu.dk) Contact: (+45)45257437 | ct@dtv.dk | ct@cvt.dk | cht@cvt.dk
Subject: Re: [rt.cpan.org #21235] Bug with Log::StdLog v. 0.0.3
Date: Thu, 31 Aug 2006 08:42:50 +1000
To: bug-Log-StdLog [...] rt.cpan.org
From: Damian Conway <damian [...] conway.org>
Christian Tønsberg via RT wrote: Show quoted text
> Thank you for (yet another) useful module!
You're most welcome. Show quoted text
> I belive I have discovered a bug.
No. This is not a bug. This is a misunderstanding of how Perl lexical variables work. It can be demonstrated by the Show quoted text
> following commandline invocations of perl: > > $ perl -e' use Log::StdLog { file=>"foo" }; print {*STDLOG} error=>"bar";' > $ perl -e'my $f="foo"; use Log::StdLog { file=>"$f" }; print {*STDLOG} error=>"bar";' > $ perl -e'my $f="foo"; use Log::StdLog { file=>$f }; print {*STDLOG} error=>"bar";' > > The first works fine. > > The second makes Log::StdLog report > > Unable to open log file '' at -e line 1 > > The third makes Log::StdLog report > > Use of uninitialized value in open at /usr/local/share/perl/5.8.4/Log/StdLog.pm line 90. > Use of uninitialized value in concatenation (.) or string at /usr/local/share/perl/5.8.4/Log/StdLog.pm line 90. > Unable to open log file '' at -e line 1 > > I cannot find anything in the documentation for Log::StdLog that > lead me to belive that filenames cannot be passed as in the second > and third example above.
They can, but you're not doing that, quite. A 'use' statement executes at BEGIN time, but a variable assignment executes at RUN time. So the $f variable is empty when it's passed to the 'use'. You need: perl -e'my $f; BEGIN{$f="foo"} use Log::StdLog { file=>$f }; print {*STDLOG} error=>"bar";' I have updated the docs to point this out explicitly: Note that, if you want to pass arguments to the C<use Log::StdLog> via variables--as in the above example--you must make sure that the variables are initialized at I<compile-time>, before the C<use> statement executes. Typically, that means you need something like: my ($filename, $min_level); BEGIN { $filename = get_filename(); $min_level = 'warn'; } use Log::StdLog { file => $filename, level=>$min_level }; Hope this helps, Damian