murphybr has asked for the wisdom of the Perl Monks concerning the following question:

I am new to perl and am having issues with this script i am using for a syslog server. I am not getting any responses from the original developer and as such bringin my issue to the perl gods for help.

I receive the following error when my program runs:

 Use of uninitialized value in numeric gt (>) at....at line 537.

the line in question is:

return ($total) if ($total > $max_nb)

the function this belongs to is:

sub Unknown_Number { my $device = shift; my $max_nb = Octopussy::Parameter('wizard_max_msgs'); my ($total, $nb) = (0, 0); my $dir = Octopussy::Storage::Directory_Unknown($device); Octopussy::FS::Create_Directory("$dir/$device/Unknown/"); foreach my $fy (glob "$dir/$device/Unknown/*") { foreach my $fm (glob "$fy/*") { foreach my $fd (glob "$fm/*") { foreach my $f (glob "$fd/*") { chomp $f; $nb = `zcat "$f" | wc -l`; chomp $nb; $total += $nb if ($nb >= 0); return ($total) if ($total > $max_nb); } } } } return ($total); }

sorry this may seem long. Any help on this would be greatly appreciated.

Replies are listed 'Best First'.
Re: uninitialized value in numeric gt (>) in perl
by halfcountplus (Hermit) on Feb 23, 2011 at 14:01 UTC

    It would seem this has to be $max_nb, since $total is initialized to 0. Ie, Octopussy::Parameter('wizard_max_msgs') is returning undef.

    You could check that by throwing in something:

    my $max_nb = Octopussy::Parameter('wizard_max_msgs'); die "$max_nb undefined!" unless (defined $max_nb);
      While I agree with halfcountplus, I would note that you could perform a simple or else set $max_nb to zero as follows
      my $max_nb = (Octopussy::Parameter('wizard_max_msgs'))||0;
      That said, the Octopussy::Parameter('wizard_max_msgs') should probably return zero if no such parameter.

      print "Good ",qw(night morning afternoon evening)[(localtime)[2]/6]," fellow monks."
Re: uninitialized value in numeric gt (>) in perl
by moritz (Cardinal) on Feb 23, 2011 at 14:00 UTC
    It's a warning, not an error. And it tells you that either $total or $max_nb is not defined.

    Since we can't run the script for you (it depends on files and functions you haven't provided to us), we can only guess why this is the case.