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

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"},
};

print $cmd_args_ref->{"log_level"};

Thx in advance,
rafailow.

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


Reply via email to