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.


Nah! Your thinking of Simon Templar, originally played by Roger Moore and later by Ian Ogilvy

In reply to Re: pattern matching through a whole document by BrowserUk
in thread pattern matching through a whole document by r_mehmed

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.