Your regexes have a problem. If you have something like $str =~ /\d/, that will match the first digit in $str. When you are validating or parsing, you usually want to provide anchors: zero-width assertions about what characteristics the string must have at that point in the regex. For instance, to parse a string with 0 or more digits followed by one or more letters, you would say:
$str =~ /^\d*[a-z]+\z/i;
where the ^ says that part of the regex can only match at the beginning of the string and \z says that can match only at the end of the string, so that no unexpected characters are allowed before or after the pattern specified.

Without the anchors, you get /\d*[a-z]+/i which will match any string that has at least one letter somewhere in it, e.g. ";!$#a-+".

(You will often see $ used instead of \z; that will match either at the end of the string or immediately before a newline character at the end of the string; sometimes handy when dealing with unchomped input, but usually not what is actually wanted.)

The meaning of ^ and $ changes when the //m flag is used, see perlre for details.


In reply to Re: more date conversion happiness, part 3 by ysth
in thread more date conversion happiness, part 3 by ctp

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.