[Omaha.pm] printf("%02d", "2007")

Jay Hannah jay at jays.net
Tue Apr 24 19:11:22 PDT 2007


On Apr 24, 2007, at 7:04 PM, Andy Lester wrote:
> On Apr 24, 2007, at 3:42 PM, Jay Hannah wrote:
>> unless ($a[0] =~ /^\w\w\w \d\d \d\d\d\d/) {
>>    die "Unrecognized date format from MS-SQL: '$a[0]'";
>> }
>> @b=split ' ',$a[0];
>
> Funny that they match a pattern, and then do the split.  Better to do:
>
> unless ( @b = ($a[0] =~ /^(\w{3}) (\d{2}) (\d{4})/ ) {
> 	die...
> }
>
> Then @b is populated.

Indeed sir. Here's one of the changes I committed today. Since the date 
format changed I cleaned up the other code (IMHO) while I was in there.


Before:

unless ($a[0] =~ /^\w\w\w \d\d \d\d\d\d/) {
    die "Unrecognized date format from MS-SQL: '$a[0]'";
}
@b=split ' ',$a[0];
$key_val = sprintf("%02d%02d%02d|%s",$mon{$b[0]},$b[1],$b[2],$a[1]);
$key_val =~ s/\s+$//;
$ret_hsh{$key_val} = $a[2];


After:

unless ($a[0] =~ /^(\d\d\d\d)-(\d\d)-(\d\d) \d\d:\d\d:\d\d/) {
    die "Unrecognized date format from $prop MS-SQL: '$a[0]'";
}
my ($y, $m, $d) = ($1, $2, $3);
$ret_hsh{"$m$d$y|$a[1]"} = $a[2];


j



More information about the Omaha-pm mailing list