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"};

In reply to Re^2: Changing the Value Assigned To A Hash Key by gnurob
in thread Changing the Value Assigned To A Hash Key by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.