in reply to Re: Generating a format template for a date
in thread Generating a format template for a date

Extension of that idea, ditching the conditionals (implicitly burying them in the regex's):
while(<DATA>){ s/9999/YYYY/; # 4-char year first s/(?<=[^9])99(?=[^9])/MM/; # month is always in the middle s/(?<!YYYY.{4})99$/RR/; # 2-char year is always at end, and won +'t have a 4-char year already s/99/DD/; # the remaining 2-chars will be the day print; } __DATA__ 99/99/9999 99/99/99 99-99-9999 99-99-99 99:99:9999 99:99:99 99+99+9999 9999-99-99 9999:99:99 9999+99+99

Replies are listed 'Best First'.
Re^3: Generating a format template for a date
by jbert (Priest) on Oct 13, 2006 at 18:01 UTC
    Nice! Doing multiple subs on the same target is something which looks nicer using the implicit $_.

    I definitely need to read up on my extended regexps though, those look-ahead/behind assertions are gnarly, dude.