• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 145
  • Last Modified:

perl error

I am geting information from user
and want to print an error message if any of the fields were empty. But i don't wanna go thorought each entry one bye one with a different if statement for each of them. Is there any way to do this all in one or some easier way of doing it rather than checking each entry ??
0
Dewaana
Asked:
Dewaana
  • 3
1 Solution
 
shlomoyCommented:
If your fields data is in an array called @fields then you can do:

foreach $field (@fields) {
      error_message() if (!defined($field));
}
0
 
shlomoyCommented:
use CGI;
@names = $query->param
foreach $name (@names) {
      error_message() if (!defined($name));
}


where error_message() is a subroutine which handles the error message you'd like to output to the user.
0
 
DewaanaAuthor Commented:
thank u very much
0
 
shlomoyCommented:
Sure.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now