Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
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.

Replies are listed 'Best First'.
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.
Re^2: Debugging "Use of uninitialized value" warnings.
by ww (Archbishop) 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.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://608268]
help
Chatterbox?
[ELISHEVA]: well then since the obvious possible mistakes on my part have been ruled out, SOPW it is.
[ELISHEVA]: the data source, or one of them, is the OECD - they provide a *lot* of data that ought to be easily available to perl programmers.
[erix]: it might be cunning to mention the module in the title... :)
[ELISHEVA]: fancy that - a title that actually describes the problem :-)
[ELISHEVA]: but actually thanks for the reminder
[Discipulus]: DBI::CSV + utf8 = BOO?M
[erix]: in extremis we tend to forget stuff ;)
[ELISHEVA]: \Disciplus : lol
[Discipulus]: and ELISHEVA we waait one your post since ~2years... ;=)
[ELISHEVA]: has it really been that long?

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (7)
As of 2017-05-28 20:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?