Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Debugging "Use of uninitialized value" warnings.

by NovMonk (Chaplain)
on Apr 04, 2007 at 13:01 UTC ( #608268=note: print w/ replies, xml ) Need Help??


in reply to Debugging "Use of uninitialized value" warnings.

I hope someone eventually answers this part of your question:

Is the best practice simply to code more defensively and explicitly check all variables are initialized prior to interpolation? I could do that, I guess, but I'm afraid of bloating the code needlessly.

because this drives me nuts, too. I am still very new to perl, at the stage where those warnings Do look like "noise" to me. I don't understand why I should have to explicitly set all my variables to a value to avoid this problem. If indeed, that's what I need to do. Particularly when the resulting output is what I want.

If anyone could point me toward some relevant pages here or in the Llama/ Camel books explaining this, I'd be very grateful.

Pax,
NovMonk


Comment on Re: Debugging "Use of uninitialized value" warnings.
Re^2: Debugging "Use of uninitialized value" warnings.
by ww (Bishop) on Apr 04, 2007 at 14:25 UTC

    NovMonk: You'll need to read about warnings (perldoc -f warn) but this may also help.

    This generates a compile-time error if you access a variable that wasn't declared via use vars, localized via my or wasn't fully qualified.

    In (perhaps oversimplified) words, Perl is exhibiting a bit of DWIMery here; "protecting you from yourself" or "helping you catch mistakes like typos in a $var name (eg $var somehow is typoed as $vqr

    ps: take the advice at the top of that page, and use perldoc to obtain a fuller explation.

Re^2: Debugging "Use of uninitialized value" warnings.
by cdarke (Prior) on Apr 04, 2007 at 14:40 UTC
    3rd Edition of the Camel, first paragraph of chapter 4, p.111 discusses this.
    Perl does not force you to program in any particular style, but most experienced programmers have made enough mistakes to know that initialising variables, like use warnings and use strict, are a Good Thing.
    Strangely I can't find a direct 'Best Practice' to initialize variables in TheDamian's book.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://608268]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (5)
As of 2014-07-12 21:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (241 votes), past polls