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

Hi Monks!

This test script is to ask what would be an alternative and why I get this warning message:
Use of uninitialized value $_[0] in string eq at /usr/local/share/perl5/CGI.pm line 2209. if I use "-w".
If I remove the "-w" and use instead "use warnings" I don't get the warning, is it because of CGI.pm been deprecated?
The version of Perl I have is v5.10.1
Any suggestions?
#!/usr/bin/perl -w use strict; use CGI qw(:standard); use CGI::Carp qw( fatalsToBrowser set_message ); my $q = new CGI; print $q->header(); my $msg = escapeHTML( scalar $q->param( 'msg' )) || 'No Msg'; my $error = escapeHTML( scalar $q->param( 'error' )) || ' No error'; my $error_msg = ($msg) ? $msg : ($error) ? $error : ''; print "<br><br>Msgs: $error_msg <br><br>"; exit;

Thanks for looking!

Replies are listed 'Best First'.
Re: Warnings using -w
by Anonymous Monk on Jun 26, 2017 at 14:14 UTC
    It's because the effect of -w is global and "use warnings" is only for the lexical scope. That's why "use warnings" is recommend nowadays.
Re: Warnings using -w
by ikegami (Patriarch) on Jun 26, 2017 at 20:11 UTC

    -w activates warnings globally, which causes escapeHTML to warn when you pass undef to it.

    Fixed:

    my $msg_html = escapeHTML( $q->param( 'msg' ) // 'No msg' ); my $error_html = escapeHTML( $q->param( 'error' ) // 'No error' );
Re: Warnings using -w
by Discipulus (Canon) on Jun 26, 2017 at 14:15 UTC
    Hello, just some hint..

    I suppose it is not because the module is deprecated: this is just an advice with no consequences.

    The fact you observe can be related to the server which serve the script; I dont know how the shebang is taken in consideration while the script is run into a web server: some of them, for sure, ignore it completely.

    The error is anyway strange..

    Which webserver are you using to serve the program? is something in the middle (like mod_perl)?

    More info you pass more easy you'll get the anser you need.

    L*

    There are no rules, there are no thumbs..
    Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.
      Nothing in the middle, using Apache Server.