By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,708 Members | 2,080 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,708 IT Pros & Developers. It's quick & easy.

only 1 line being processed?

P: n/a
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?!

Thanks

Geoff
Jul 15 '08 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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;
}
Jul 16 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.