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

Hey

When using warnings (#!/usr/bin/perl -w), I recieve the following warnings: First time I came across this:
Use of uninitialized value in concatenation (.) or string at E:\Web Si +tes\Contrarian Investments\Contrarian-Investments Web folder\signup.p +l line 98. Use of uninitialized value in concatenation (.) or string +at E:\Web Sites\Contrarian Investments\Contrarian-Investments Web fol +der\signup.pl line 98. Use of uninitialized value in concatenation (. +) or string at E:\Web Sites\Contrarian Investments\Contrarian-Investm +ents Web folder\signup.pl line 98. Use of uninitialized value in conc +atenation (.) or string at E:\Web Sites\Contrarian Investments\Contra +rian-Investments Web folder\signup.pl line 98. Use of uninitialized v +alue in concatenation (.) or string at E:\Web Sites\Contrarian Invest +ments\Contrarian-Investments Web folder\signup.pl line 98.


Line 98 goes as:
$error_html = "<font size=\"2\" face=\"verdana\" color=\"#CCCCCC\"><b> +Please fix the following errors:</font><font size=\"1\" face=\"verdan +a\" color=\"#003471\"><br>$error_msg_x<br>$error_msg_xx<br>$error_msg +_xxx<br>$error_msg_pw_xxx<br>$error_msg_pw_x<br>$error_msg_pw_xx<br>$ +error_msg_terms<br>$error_msg_email<br>$error_msg_city<br>$error_msg_ +state<br>$error_msg_date<br>$error_msg_zip<br></b></font>";


Its a scalar mixed with a little html and a bunch of error scalars produced from a sign up form. If I take out the warnings option, it produces no warning message, and therefore my HTML looks as planned.

Once I call the function &sign_html($error_html); is when I see the warning messages.

Should I continue to use Warnings option and try to fix the warning messages? It seems as the scalar produces the warning errors, when replacing $error_html = "hey"; , the html prints fine with no warnings.

Thank you
Anthony

Replies are listed 'Best First'.
Re: Warnings, strict HTML scalar
by demerphq (Chancellor) on Mar 11, 2004 at 09:30 UTC

    That statement is just asking for a rewrite. Adding or removing new vars is a pain, finding vars is a pain, reading it is a pain, and if the errors are empty you end up with empty lines in the output. Also learn to use qq() and q() instead of "" and '' when you have to include the quote chars inside. Anyway. The following is something like the way an older hand might write this.

    $error_html = join "<br />\n", qq(<font size="2" face="verdana" color="#CCCCCC">) . qq(<b>Please fix the following errors:</font>) . qq(<font size="1" face="verdana" color="#003471">), (grep { defined $_ } $error_msg_x, $error_msg_xx, $error_msg_xxx, $error_msg_pw_xxx, $error_msg_pw_x, $error_msg_pw_xx, $error_msg_terms, $error_msg_email, $error_msg_city, $error_msg_state, $error_msg_date, $error_msg_zip ), "</b></font>\n" ;

    I have concerns that these error variables are inappropriate. Maybe you should have an @errors array and when you encounter an error do something like:

    push @errors,"<b>Password:</b> You must enter a value";
    And then you could replace the list of vars there with @errors and lose the grep (actually everything inside that (grep ...) expression)

    Also there is a possible issue that if your error message contains html or html characters that it should actually be escaped before printing. This may not be an issue for you, but its worth keeping in mind.

    hth


    ---
    demerphq

      First they ignore you, then they laugh at you, then they fight you, then you win.
      -- Gandhi


Re: Warnings, strict HTML scalar
by borisz (Canon) on Mar 11, 2004 at 08:19 UTC
    This means one or more of your scalars in line 98 have a undef value. check:
    $error_msg_x $error_msg_xx $error_msg_pw_x $error_msg_pw_xxx $error_msg_pw_xx $error_msg_city $error_msg_state $error_msg_date $error_msg_zip $error_msg_email
    Boris
Re: Warnings, strict HTML scalar
by matija (Priest) on Mar 11, 2004 at 08:21 UTC
    Yes, you should fix warnings, unless you absolutely know what you're doing, and why the warning doesn't apply. Which doesn't appear to be the case here.

    From the error, it seems to me that the variables $error_msg_x, $error_msg_xx etc are undefined.

    If you want them empty, but also want to avoid the warning, initialize them to "" (the empty string).

Re: Warnings, strict HTML scalar
by TomDLux (Vicar) on Mar 11, 2004 at 18:54 UTC

    The warning message refers to variables, but I would say the error in your code is having hard-coded print statements to define your web page.

    The best solution would be to have the page layout in an external file, and to substitute data values into parrticular places using HTML::Template, or Template::Toolkit, or another such templating module.

    If for some reason it's not appropriate to use an external file, investigate the HTML formatting routines in CGI.pm.

    --
    TTTATCGGTCGTTATATAGATGTTTGCA