On Tue, 2008-08-05 at 01:05 +0200, rafailowski wrote:
> Hi all,
> 
> I have a problem with Getopt::Long and Log::StdLog.
> 
> An example script, i always have the following error :
> Use of uninitialized value in hash element at 
> /usr/local/share/perl/5.10.0/Log/StdLog.pm line 57
> 
> level => $cmd_args_ref->{"log_level"} is always undef(???) but
> print $cmd_args_ref->{"log_level"}; return the good value

$cmd_args_ref->{"log_level"} is undef unless you set with a command-line
argument.

> 
> I try to fix this with BEGIN block (around GetOptions) with no success
> 
> Is there a way to solve this (BEGIN INIT block?)
> 
> #!/usr/bin/perl
> 
> use warnings;
> use strict;
> use Getopt::Long;
> 
> my %cmd_args = ();
> my $cmd_args_ref = \%cmd_args;
> 
> GetOptions(
>     "log-level=s"   =>  \$cmd_args{"log_level"},
> );
> 
> sub log_format {
>     my ($date, $pid, $level, @message) = @_;
>     return "[$date][$level]: " . join(q{}, @message);
> };
> 
> use Log::StdLog {
>     format => \&log_format,
>     file => "$0.log",
>     level => $cmd_args_ref->{"log_level"},

    level => ( $cmd_args_ref->{"log_level"} || 'none' ),

> };
> 
> print $cmd_args_ref->{"log_level"};
> 
> Thx in advance,
> rafailow.
> 
-- 
Just my 0.00000002 million dollars worth,
  Shawn

"Where there's duct tape, there's hope."

"Perl is the duct tape of the Internet."
        Hassan Schroeder, Sun's first webmaster


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to