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

Re: need regular expression

by davido (Cardinal)
on Nov 02, 2005 at 08:46 UTC ( [id://504867]=note: print w/replies, xml ) Need Help??


in reply to need regular expression

The following will work correctly if the year is specified as 0, 1, 11, 111, or even 1111 (ones representing any digit):

use strict; use warnings; my( @dates ) = ( '4-10-31', '14-11-31' ); foreach my $date ( @dates ) { my $string = $date; $string =~ s/^(\d+)/ my $year=2000; substr($year,4-length($1),length($1))=$1; $year/e; print $string, "\n"; }

You can even override '2000' as being the base year by including the entire four-digit year, as in "1987-10-31".


Dave

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://504867]
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: (2)
As of 2024-04-20 13:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found