On Mon, 2008-08-04 at 20:47 -0400, Mr. Shawn H. Corey wrote:
> On Tue, 2008-08-05 at 01:33 +0200, rafailowski wrote:
> > 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???
> > 
> > 
> 
> Sorry, I was thinking about the problem correctly.  Try:
> 
> #!/usr/bin/perl
> use Getopt::Long;
> use Log::StdLog;
> 
> 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);
> };
> 
> Log::Stdlog::import( {
>     format => \&log_format,
>     file => "$0.log",
>     level => $cmd_args_ref->{"log_level"},
> } );

Oops, try this instead:

Log::Stdlog::import {
    format => \&log_format,
    file => "$0.log",
    level => $cmd_args_ref->{"log_level"},
};


> 
> print $cmd_args_ref->{"log_level"};
> 
> __END__
> 
> This re-runs the import function after the program has started.
> 
> -- 
> 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
> 
> 
-- 
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