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

Hi monks,

I'm getting the error "Use of uninitialised values..." from the following code:

my %hash = @_; $hash{'from'} ||= 0; if ($hash{'from'} eq 'main') { # code }
There's probabaly something wrong there but I can't figure out what. How do I modify the code to rid the error message?

Thanks in advance :)

Update:Thanks to all. My apolgoies, the above snippet isn't the culprit, I'll look at other parts of the code to pinpoint where the error comes from. Will post the result here.

Replies are listed 'Best First'.
Re: Help on uninitialised values
by davido (Cardinal) on Jul 28, 2004 at 15:45 UTC

    I have tested the code with a variety of possibilities for @_, and can't find any combination that causes the code posted to report "Use of uninitialized values". There must be something else going on we're not seeing.


    Dave

      Thanks, davido :)

      The error log lists several lines of that errors: Use of uninitialised values at Mymodule.pm line 771.

      On my editor, I did a go to line 771 and couldn't find anything suspicious. The only piece of code that could trigger that error in the region of line 711 is the snippet I gave.

      I'll examine the code around line 711 in more detai...

Re: Help on uninitialised values
by Aristotle (Chancellor) on Jul 28, 2004 at 16:17 UTC

    The code you posted as is can never lead to that warning.

    Makeshifts last the longest.

Re: Help on uninitialised values
by ccn (Vicar) on Jul 28, 2004 at 15:53 UTC

    In the warning message you can see a number of a problem line. It'will be useful if you post this line here.

Re: Help on uninitialised values
by keszler (Priest) on Jul 28, 2004 at 16:14 UTC
Re: Help on uninitialised values
by wfsp (Abbot) on Jul 28, 2004 at 15:49 UTC
    Compiles and runs ok on winXP/activestate. Are you sure that is the all code you're trying to run?
      Please read my reply to davido. I'm now trying to examine the code for the possible source of that error. Thanks :)
Re: Help on uninitialised values
by shemp (Deacon) on Jul 28, 2004 at 15:50 UTC
    are you positive that the warning is coming from whats posted, or from the section of #code ?