Geoff Cox wrote:
Hello
I have a file called fs-test.txt which has in it
7/7/2008
9/7/2008
and a pl file
use warnings;
use strict;
open (IN, "fs-test.txt");
open (OUT, ">new-fs-test.txt");
while (defined (my $line = <IN>) ) {
if ( $line =~ /^(\d{1,2})\/(\d{1})\/2008.*? /
) {
print OUT "0$2-0$1-2008 \n";
}
}
Why is it that only the first date is being processed?!
Probably because the second line does not have a blank after the "8".
Why are you not allowing dates after the 9th of the month?
Why are you outputting three digits for October, November, and December?
Why are you not using sprintf?
Why are you not posting to comp.lang.perl.misc? (comp.lang.perl is defunct.)
-Joe
#!/usr/bin/perl
use strict; use warnings;
while(<>){
s:^(\d{1,2})/(\d{1,2})/(\d{4}):sprintf('%02d-%02d-%d',$2,$1,$3):e;
print;
}