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

How can I check which fields are empty and then list them on a page? I know how to check if they are empty, but how do I find out which ones? I know, of course, that I could use:
if ($field eq "") { if ($nextfield eq "") { et cetera } }
But isn't there an easier way?

Replies are listed 'Best First'.
Re: Empty Fields
by Zaxo (Archbishop) on Apr 09, 2002 at 20:44 UTC

    If you are getting them from a cgi post, the empty fields will not be sent by most browsers, Have a list of the fields you require, @required, and check cgi params against that. grep is a good way to avoid clutter.

    my @needed = grep {!$cgi->param($_)} @required; if (@needed) {...};

    After Compline,
    Zaxo