in reply to Data normalisation

First off, kudos on that regex. Very spiffy. Are you aware of qr/REGEX/ in newer Perls?

As to the problem at hand, yes, you're going to have to use capturing parens and manipulate the results. Something like the following in your if condition:

if ((($month, $day, $year) = /($month)($day)($year)/io) || (($day, $month, $year) = /($day)($month)($year)/io)) { .... }

Then, the question becomes, what goes in the "...."? I'll assume you have a plan in mind for $year, and $day doesn't require anything unless you want to do verification. My suggestion for $month is a hash that looks something like this:

JANUARY => 'Jan', FEB => 'Feb', FEBRUARY => 'Feb', .... DEC => 'Dec', DECEMBER => 'Dec');

Then you can so something like:

printf('%02d-%s-%04d', $day, $mhash{uc $month}, $my_year);

where $my_year is something you calculated from $year.

Of course, if you want to validate the day first, you could augment %mhash something like this:

my %mhash = (JAN => {Name => 'Jan', Days => 31}, ....

And print like so:

printf('%02d-%s-%04d', $day, $mhash{uc $month}{Name}, $my_year);

That was probably more answer than you needed, but there ya go.

*Woof*

Replies are listed 'Best First'.
RE: Re: Data normalisation
by splinky (Hermit) on Jul 06, 2000 at 17:46 UTC
    Actually, I need to amend the above a bit. Looking at your regexes again, I just realized that you'll have to put some capturing parens in them to keep everything happy, and stick undefs in the "if" clause accordingly.

    E.g.,

    $day = '([0-3]?[0-9])(?:th|st|nd|rd)'

    And in the if, something like:

    if ((($month, undef, $day, $year) = /($month)($day)($year)/io) ||

    I didn't go through your regexes and if clauses and give you the exact solution, but I think you get the idea.

    *Woof*