467,104 Members | 998 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,104 developers. It's quick & easy.

only 1 line being processed?

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
  • viewed: 1342
Share:
1 Reply
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.

Similar topics

2 posts views Thread by Mantorok Redgormor | last post: by
1 post views Thread by vishal | last post: by
6 posts views Thread by James Pascoe | last post: by
3 posts views Thread by Branco Medeiros | last post: by
7 posts views Thread by Sin Jeong-hun | last post: by
11 posts views Thread by xdevel | last post: by
7 posts views Thread by J.H.Kim | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.