in reply to Re: Changing the Value Assigned To A Hash Key
in thread Changing the Value Assigned To A Hash Key
I had wondered if == "1" was the best technique. This is alllmost my first ever Perl script.
A number of quick functions are used to check user data against input criteria (for checking telephone numbers, postal codes, etc.). The code below is for checking a persons first or last name; one of many checks on this form. All we want to do is verify that more than two characters of an acceptable type are used.
sub check_name { my $name = $_[0]; if ($name =~ /^[A-Z][A-Za-z\-']{2,40}/s) { return 1; } else { return "Friendly message..."; } }
I wanted to return true or false, but wasn't sure how to incorporate an error message anywhere in the many scripts that call this function. It seemed OK to return a true of OK and a string warning if bad. Running with that idea, the "($first_name_check == "1")" test seemed to be the way to go.
It crossed my mind to move the all error messages to a seperate file and return error codes greater than one as index references in the seperate error message file. I haven't seen any good examples of accomplishing this task and would certainly appreciate suggestions on where to go look/read. (All I have is an old Perl cookbook that just seems wrong...
Switch undef around. Thanks for both your suggestions
# was $app{"first_name"} = ""; switch to next line undef $app{"first_name"};
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Changing the Value Assigned To A Hash Key
by cog (Parson) on Feb 08, 2005 at 21:23 UTC |