The content of 'input.txt'#C:\strawberry\perl\bin\perl.exe my $filename = "input.txt"; open my $file, '<', $filename; @fileinput=<$file>; close($file); #while($file) #{ my $line =$_; # $line=~s/(\d{2}\/\d{2}\/\d{4})/($3\/$1\/$2)/g; #print "@listinput"; # change date format foreach $line(@fileinput) { my $testdate=($line); #= "11/09/2009"; if($testdate =~s/(\d{2})\/(\d{2})\/(\d{4})/$3\/$1\/$2/g) { print $testdate; #=~s/(\d{2}\/\d{2}\/\d{4})/($3\/$1\/$2)/; } if($testdate =~s/(\d{4})(\d{2})(\d{2})/$1\/$2\/$3/) { print $testdate; } if($testdate =~s/(\w{4})\s(\d{2})\,\s(\d{4})/$3\/$1\/$2/) { print $testdate; } if($testdate =~s/(\d{2})\-(\d{2})\-(\d{4})/$3\/$1\/$2/) { print $testdate; } } #Wrong,It also change the date #foreach $line(@fileinput) #{ #my $numToword=($line); #$num = "9"; #$word = "nine"; #if($numToword =~s/$num/$word/g) # { # print $numToword; # } #$num = "19"; #$word = "nineteen"; #if($numToword =~s/$num/$word/g) # { # print $numToword; # } #$num = "10"; #$word = "ten"; #if($numToword =~s/$num/$word/g) # { # print $numToword; # } #$num = "5"; #$word = "five"; #if($numToword =~s/$num/$word/g) # { # print $numToword; # } #} # Capilize the first character after AU: foreach $line(@fileinput) { my $Cword=($line); if($Cword=s/(^AU:\s[a-z])/(^AU:\s[A-Z])/) { print $Cword; } } #extract ID in () foreach $line(@fileinput) {my $extractid=($line); if($extractid =~m/\( (\d+)\)/g) { print $extractid; } } #remove END, end word in file foreach $line(@fileinput) { my $removeend=($line); if($removeend=~s/(^END) | (^end) | (END$) |(end$)//g) { print $removeend; } } #$line=~s/(\d{2}\/\d{2}\/\d{4})/($3\/$1\/$2)/g; #print $line; #}
the changes will be put in output.txt, thank you for the helpDD: 11/09/2009 AU: jas dimaano PP: Employee ID list PP: (489459) Jas = DS16 -> with SPi since 2005/04/04 AND with ECO ever + since PP: Sam = FT35 -> resigned last 09-03-2008 PP: Evan = AT89 -> transferred last 20070605 to Journals PP: there's more... === DD: july 11, 2009 AU: Jr s. Tolentino, -editor PG: page 9 PP: Earn points now! PP: Yes! You heard it right! (635436) PP: Finish your exercise before the deadline and you'll receive additi +onal points. PP: Even if you're early by 10, 5 or even 1 minute, we'll give away th +e corresponding points! PP: So hurry now and ensure that you'll be able to finish ASAP! END PP: === DD: 10-09-2009 AU: mr. Henderson de la cruz (h.delacruz@yahoo.com) VL: volume IV. PG: page 19 PP: This is only a test document. PP: Did you know that this is just a test doc? See if you're end outpu +t (if you'll be able to produce 1) will be the same as the required o +ne. PP: Don't build you're house on a sandy land. And not too near the sho +re as well. PP: Perhaps you'll earn more than 10-50k of money! Why not?! This does +n't make any sense. Right? So I better end this now. PP: This is the end of this test document. ===
In reply to Regular expressions extract, change num to word and capitalize each word after AU: tag and add 'written by' by allison
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |