Mr. Shawn H. Corey wrote:
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.
Yes, without argument, the error is normal :
$ perl test.pl
Use of uninitialized value in hash element at
/usr/local/share/perl/5.10.0/Log/StdLog.pm line 57.
Use of uninitialized value in string at test.pl line 25.
But with an argument like this :
$ perl test.pl --log-level=info
Use of uninitialized value in hash element at
/usr/local/share/perl/5.10.0/Log/StdLog.pm line 57.
info
level => $cmd_args_ref->{"log_level"} stay undef and
print $cmd_args_ref->{"log_level"}; return the good value.
I don't understand why in : use Log::StdLog {...}, the value of
$cmd_args_ref->{"log_level"} stay always undef???
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/