Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

Re^2: need regular expression

by ioannis (Prior)
on Nov 02, 2005 at 10:55 UTC ( #504892=note: print w/replies, xml ) Need Help??

in reply to Re: need regular expression
in thread need regular expression

This formula is simpler than the one earlier. The main insight here is to avoid strings; it is better to use arithmetic addition to construct the 'year' string (i.e. 20xx) .
for ( my @dates = qw( 4-10-31 14-11-31 ) ) { s/ ^ (\d{1,2}) ((?:-\d{1,2}){2}) $ /(2000+$1).$+/xe and print; }

Replies are listed 'Best First'.
Re^3: need regular expression
by Perl Mouse (Chaplain) on Nov 02, 2005 at 11:13 UTC
    I prefer to use strings - in that case, it becomes easy to deal with 3 or 4 digit years as well:
    my @dates = qw /4-10-31 14-11-31 1979-10-10/; for (@dates) { s/(\d+)/substr("2000", 0, -length($1)).$1/e; print "$_\n"; } __END__ 2004-10-31 2014-11-31 1979-10-10
    Perl --((8:>*

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://504892]
[Tanktalus]: perldigious: I'm not looking to get rich. I'm looking for interesting work, with good continuity of employment, and maintenance of our current lifestyle. (An improvement wouldn't be bad, either, but that's not a requirement ;) )
erix enjoys the confusion++
[Your Mother]: :P
[Tanktalus]: Without confusion, I'd be out of a job ;)
[Tanktalus]: Already. :D
[Lady_Aleena]: Your Mother, I wish it did have a way to put in a directory to search.
[Your Mother]: Thatís silly. Itís a string op tool.
[Lady_Aleena]: So I guess I'll go argue with File::Find and grep.
[Your Mother]: I would probably use Path::Tiny instead for it's slurp and such.
[Your Mother]: s/it's/its/

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (7)
As of 2017-05-23 19:37 GMT
Find Nodes?
    Voting Booth?