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

I've been porting old scripts to mod_perl that use CGI.pm (3.20) and came across a persistent error "Use of uninitialized value in concatenation (.) or string" caused by the start_html function. CGI OO interface was in use with the following params supplied to start_html: title, bgcolor, text, link, vlink, and style. I could not find a way to supress the error. The same code worked perfectly under mod_cgi. Is this a known problem?

Replies are listed 'Best First'.
Re: CGI::start_html and mod_perl
by davorg (Chancellor) on Jul 06, 2006 at 07:44 UTC

    A warning is just what is says. It is warning you about a potential problem with your code. Now you could just suppress it and hope that it's not warning you about a serious error[1]. Or you could investigate it and put right whatever is causing the error.

    In this case you're probably using a variable that you haven't put any data into. Fixing the problem might well be as easy as initialising the variable with an empty string.

    [1] And if you want to do that then perllexwarn will show you how.

    --
    <http://dave.org.uk>

    "The first rule of Perl club is you do not talk about Perl club."
    -- Chip Salzenberg

      I love you guys. I really did mean "warning" rather than "error", sorry about that. My use of warnings is religious so I know what causes them too. I tried the common methods of turning them off in the block where start_html occurs but that didn't work. There were no empty variables since start_html was called with a few hard coded parameters. This occured under the PerlRun handler in the initial phases of porting old code to Registry and handlers. One aspect of our procedure replaces CGI with Apache::Request so we'll remove CGI HTML routines to solve this problem.

      Just wondering if anyone knew about this because it took some time to find the problem and the source was so unexpected.

Re: CGI::start_html and mod_perl
by CountZero (Bishop) on Jul 06, 2006 at 05:50 UTC
    It is not an error but a warning, so you can "hide" it by not activating warnings. I have seen this type of error many times, but other than it is estheticaly not pleasing, it does not necessarily mean that something is badly wrong.

    IMO, all it means is that you were using a variable before it was properly initialised, IOW the variable exists but has no content (yet): so either there is something wrong with the logic flow of your program or you indeed intended to use the variable without content.

    I have seen it sometimes appear in complicated print statements which internally are complied as a lot of concatenation operations. Lots of times however it is mostly harmless.

    CountZero

    "If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law

      It is not an error but a warning, so you can "hide" it by not activating warnings

      In my opinion, hiding warnings is a terrible idea. And the worst way to do it is to just remove use warnings from the code. That stops you from knowing about any warnings that might appear anywhere in your code. That sounds like coding without a safety net for no good reason.

      If you do have a piece of code where you want to "hide" a warning then just hide that specific warning in that specific piece of code. In this instance, that might look a bit like this:

      { no warnings 'uninitialized'; print start_html(...); }

      That way you still get the benefit of use warnings throughout most of your code.

      --
      <http://dave.org.uk>

      "The first rule of Perl club is you do not talk about Perl club."
      -- Chip Salzenberg

        I fully agree with your point of view. It is only once you have ascertained that the warning has no cause in a programming error that you should "hide" it.

        CountZero

        "If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law