One way to do this is to use the substitution operator s/// (see perlfunc and perlop) and use the e modifier to executed a small 'program' in the second part of the operator. By using arrays to store your months and day endings, you greatly simplify the logic of the code.
#!perl use strict; my @months = qw( -- January February March April May June July August +September October November December); my @dayends = qw( -- st nd rd th th th th th th th th th th th th th t +h th th th st nd rd th th th th th th th st); while(my $date = <DATA>) { chomp $date; $date =~ s!(\d{1,2})(\/|\-)(\d{1,2})(\/|\-)(\d{2,4})! $1 . $dayend +s[$1] . ' ' . $months[$3] . ' ' . $5 !eg; print $date, $/; } __DATA__ 3/3/2002 5/11/2002 31-07-2002 1-4-02 21-2-02 31-12-2002
Gives output
c:\test>209700 3rd March 2002 5th November 2002 31st July 2002 1st April 02 21st February 02 31st December 2002 c:\test>
Maybe you can adapt this to your purposes.
In reply to Re: pattern matching through a whole document
by BrowserUk
in thread pattern matching through a whole document
by r_mehmed
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |