in reply to Annoying 'Use of uninitialized value in concatenation' warning

Yet, it's perfectly fine for an array to contain some values of undef. Why shouldn't I be allowed to print them?

Because you cannot "print undef"!

Without the warning, there is no way to distinguish between print ''; and print undef;.

Which may be fine in some contexts, but can be strongly indicative of a serious error in others.

Hence the warning is optional and turn on and off able. You can choose to turn it off in individual blocks of code, or if you feel it never benefits you, turn it off at the top of the module: use warnings; no warnings 'uninitialized';

It's a shame there isn't a better syntax for enabling everything except one or two categories.


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

Replies are listed 'Best First'.
Re^2: Annoying 'Use of uninitialized value in concatenation' warning
by johnny_carlos (Scribe) on Oct 25, 2011 at 20:31 UTC
    I agree with BrowserUk, I think it's important to know when you are trying to use an initialized variable. Good to know that you can turn it off when needed. Your other option is to used empty strings instead of undef.
Re^2: Annoying 'Use of uninitialized value in concatenation' warning
by locked_user sundialsvc4 (Abbot) on Oct 26, 2011 at 02:07 UTC

    I also agree ... completely.

    “Warnings are your friends,” because the only party that can realistically tell you what a computer program is doing wrong is ... the computer itself.   Nevertheless you may decide that there are specific places in your program where an innocuous condition such as this one is causing a boatload of unwanted error-messages, e.g. in an Apache error log, and therefore you justifiably want to stamp the message out because it’s doing more harm than good.   In those cases, Perl does allow you to do that.   And, as BrowserUK wisely suggests, when you elect to do such a thing, you ought to do so in a very targeted way.   Suppress only the specific warnings you need to suppress, and do so only within a limited section of the code.   (I further advise that you add detailed comments surrounding the area:   “exactly what are you intending to suppress, and exactly why.”   Copying a representative handful of the actual message-texts and pasting them right into the comment-block is a pretty good idea to me, ’cuz you will forget these things.)

    Fav’d.