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

I am writting a user logon page, and want to add an error check to it so that if the username or password field are left blank an error message is printed to the screen. I have been trying the following ways of doing this
if($username eq null) { display_error_message(); }
This is bringing back an internal software error. Can anybody see why this is happening? Thanks

Replies are listed 'Best First'.
Re: creating an error message
by rhesa (Vicar) on Dec 10, 2006 at 19:41 UTC
    null is not a Perl keyword. You probably want if( !defined $username ) or if( $username !~ /\S/ ). Or maybe both.

    Also don't forget to print a http header before printing any content.

Re: creating an error message
by Old_Gray_Bear (Bishop) on Dec 10, 2006 at 22:31 UTC
    You might want to consider adding one more line to your code:
    use warnings;
    If you do, you will get the following message:
    Unquoted string "null" may clash with future reserved word at line ... +."
    I'd personally make it two lines:
    use strict; use warnings;

    ----
    I Go Back to Sleep, Now.

    OGB

Re: creating an error message
by PockMonk (Beadle) on Dec 10, 2006 at 20:25 UTC
    If this is a CGI app or similar, adding the following at the top of your script will help in returning more detailed errors for problems such as this than simply "500 internal server error":
    #!/usr/bin/perl -w # as normal use strict; use warnings; use CGI::Carp "fatalsToBrowser";
    Dan
Re: creating an error message
by Joost (Canon) on Dec 10, 2006 at 19:53 UTC
Re: creating an error message
by ysth (Canon) on Dec 10, 2006 at 20:30 UTC
    The "internal software error" probably means your perl program threw an error, the text of which ended up in the server's error log. If you have no access to the error log (for any reasonable development environment, you really should) see CGI::Carp.