Connecting Tech Pros Worldwide Help | Site Map

only 1 line being processed?

  #1  
Old July 15th, 2008, 08:45 AM
Geoff Cox
Guest
 
Posts: 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
  #2  
Old July 16th, 2008, 07:25 AM
Joe Smith
Guest
 
Posts: n/a

re: only 1 line being processed?


Geoff Cox wrote:
Quote:
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;
}
Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
Printing a "status " line from a python script Chris Seymour answers 4 November 13th, 2008 06:25 AM
Script works only with firebug installed, or in non-mozilla RossRGK answers 6 October 30th, 2008 08:25 PM
Output Parameter not being returned correctly - DAAB in ASP.NET WAP Alec MacLean answers 8 September 18th, 2006 09:35 PM
Displaying a count of records that have been processed dgardner@twcny.rr.com answers 2 August 20th, 2006 12:05 AM