Steve Bertrand wrote:
John W. Krahn wrote:
Steve Bertrand wrote:
if ( $month !~ m{ \A \d{4}-\d{2} \z }xms ) {
print "\nInvalid date parameter. Must be supplied as 'YYYY-MM'\n\n";
exit;
You exit the program if $month is not equal to a seven character string.
ehhh.. *scratching head while thinking about dragons*.
Is my regex at least doing what you perceive it should be doing? It
tests ok here:
% perl -e '$var="aaaa-bb"; print 1 if $var !~ m{ \A \d{4}-\d{2} \z }xms'
I'm so confused :P
A seven character string is *always* true.
$radius->aggregate_monthly( { month => $month } );
}
else {
So this branch will *never* execute, and the whole test is superfluous.
...but it works for real against the real database, and I get proper
results (with my original code in the OP posting).
Probably better as:
if ( $month =~ /\A\d{4}-\d{2}\z/ ) {
$radius->aggregate_monthly( { month => $month } );
}
else {
print "\nInvalid date parameter. Must be supplied as 'YYYY-MM'\n\n";
exit 1; # non-zero exit lets the OS know an error occured
}
...I think I get what you are saying, and I think I found that out in
the last message I sent.
However, I still don't understand why you claim that my original regex
was looking for a "seven character string",
The pattern /\A\d{4}-\d{2}\z/ is anchored at the beginning and end and
matches exactly four \d characters followed by a '-' character followed
by exactly two \d characters hence it will match exactly seven characters.
when I *thought* I was
checking for four digits, then two digits separated by a dash (or
hyphen, as it were).
Yes, seven characters, four digit characters, then two digit characters
separated by a hyphen character (or dash, as it were.)
John
--
The programmer is fighting against the two most
destructive forces in the universe: entropy and
human stupidity. -- Damian Conway
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/