Hello htmanning,

I'm trying to recognize numbers in a variable and return an error if a number is detected. For example, there is no reason to have a number in the "name" field.

I think this approach is, potentially, a maintenance nightmare in the making. Coming back to the code in, say, 6 months time: Did you mean to allow semicolons, commas, tab characters? To exclude the West Arabic (Latin alphabet) digits 1, 2, 3, ..., but allow their East Arabic equivalents ٢, ٣, ١, ...? If it’s at all possible, it will be much better to specify explicitly what a “name” is allowed to contain:

my $name_re = qr/^[- A-Za-z]+$/; ... unless ($name =~ $name_re) { warn "Bad name '$name'"; ... }

Then if, down the track, you find that additional characters are needed (e.g., should underscores be allowed?), they can be added once to $name_re, and the code remains clear and self-documenting.

Hope that helps,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,


In reply to Re: Recognizing numbers by Athanasius
in thread Recognizing numbers by htmanning

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.