While you are correct, I like to keep to what I think are best practices in my regular coding.
Of course, you shall keep on on your best practices. But there are more best practices than only one. One is to program very efficient, the other is to guarantee a simple maintainance and readability. Both ways are there for avoiding problems in the future, but there is no best best practice.
I would have also used the /^(...|...|...)$/ way. My most important reason would have been, that it is easier to read. The extra ?: doesn't have an influence to the algorithm done by the program, it only influences the internal way Perl is handling the regexp and its global variables. But the two extra character are confusing our eyes, making it a bit (really only a bit, but why should I renounce it) more difficulty to understand the algorithm some years later.
That doesn't mean, you're on the the false way, I only wanted to clarify that it is correct to give a beginner a simple, but (still) productive way, unless the speed penalty really hurts.
You gave another excellent example:my $mth = ( split(/\s+/, localtime) )1;I would have written it either as:
use POSIX qw/strftime/; my $month = strftime "%m", localtime;or
use Date::Simple; my $today = Date::Simple->new; my $month = $today->month;allthough both ways are much slower than your suggested one. Both have the benefit that you don't need to know what the magic 1 is referencing in the time array to (what can be a great benefit if some other or myself in one year) has to maintain the code. (In addition you can avoid extra calculations to the month as they range in the natural 01-12 or 1-12 way and not from 0..11)
In reply to Re: Re: Re: Re: Re: Code review: validation regexes
by bigj
in thread Code review: validation regexes
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |