With that said, I'd like to comment on your counterpoints.

I didn't want to offense you, all I wanted to say is there are more than one way to do it, and they are all acceptable.

If you don't use (?:..|..|..), do you also not use ?!, ?=, ?<, ?>, ?<=, ?>=, ?{}. Its a shame to give up the functionality provided by these idioms, simply due to the fact that they look funny.

In fact, I like to use the non-capturing groups, positive/negative look aheads and behinds and closefisted regexp parts. I use them where they are implied by the algorithm. (In doubt, I choose the way with the least type strokes and the least reading effort). The ?: construct is needed when we want to capture some parts, and some other group parts are only needed for simple grouping. In addition, the ?: construct is important, if the regexp is reused in other regexps (e.g. build with the qr-operator). In the OP's case, he only wanted to find out whether a string is exactly one of some alternatives. In that case you need a group consisting of the alternatives and enclosed by the ^ and $. It doesn't matter whether it is captured or not and in doubt I would prefer the easier solution. The ?: solution is not worse, nor better as you wrote for this task. (It's perhaps only a bit quicker, but for the price of a longer and a bit more complicated script).

In terms of my way of collecting a month versus your way. It appears that you didn't actually test the line to see what ends up in $mth, but rather assumed it was the numerical value, which it is not.

To say the truth, I confound the list to the scalar context and I also confound the min of the doc as mon(th) :-( But please note, that it is also simple to get confused, as the list context is suggested by the (...)[1] part, allthough it comes from a split. Of course, it was my error, but as I think making errors is typical for humans - at least for me - thus I prefer to program as directly as possible. That involves, trying to express the algorithm without any indirection. A split call has nothing to do with time per se, the (from me called magical) 1 has nothing to do with months per se, it is only technical. Of course, it is a common idiom, but the algorithm is hided on the first glance.

In contrast, my prefered solution my $month = strftime "%b", localtime; is at least not more cryptic, it's shorter and for a lot of typical date formats, there are handy, simple to understand shortcuts (like %d for day, %m for month (number), %y for year, %w for weekday(number) and so on). It is simple to change and often simple to understand, even without a manual.

Don't misunderstand me, I don't want to say, that your style is wrong. Indeed, I like it also. But it is also a good style to program in another way and it is also quite full acceptable to advert readability and error preventing style.

Greetings,
Janek

In reply to Re: Re: Re: Re: Re: Re: Re: Code review: validation regexes by bigj
in thread Code review: validation regexes 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.