Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: Matching Date

by fenLisesi (Priest)
on Oct 13, 2006 at 17:24 UTC ( [id://578180]=note: print w/replies, xml ) Need Help??


in reply to Matching Date

Here is a solution with Regexp::Common:
use strict; use warnings; use Regexp::Common qw(time); my $DATE = $RE{time}{mdy4}{-keep}; my @dates = qw( 01/02/2006 1/2/2006 11/22/2006 12/1/2006 13/1/2006 2/35/2006 1/2/06 ); for my $date (@dates) { my ($whole, $mon, $day, $year) = $date =~ $DATE; if (defined $whole) { printf "%10s => (%2s, %2s, %s) => (%02d, %02d, %d)\n", $whole, $mon, $day, $year, $mon, $day, $year, ; } else { printf "%10s => No match\n", $date; } }
which prints:
01/02/2006 => (01, 02, 2006) => (01, 02, 2006) 1/2/2006 => ( 1, 2, 2006) => (01, 02, 2006) 11/22/2006 => (11, 22, 2006) => (11, 22, 2006) 12/1/2006 => (12, 1, 2006) => (12, 01, 2006) 13/1/2006 => No match 2/35/2006 => No match 1/2/06 => No match
Hope this helps.

Update: Added <readmore>

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://578180]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (5)
As of 2024-04-19 12:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found