in reply to Combining s///

My take on this matter is somewhat ruled by the philosophy Dictum Ne Agas:   Do Not Do a Thing Already Done.”

“Date manipulation,” of any sort, definitely qualifies as “a thing already done.” Therefore, instead of writing Yet Another One, surf through CPAN and look for any one of a dozen good, highly-rated date manipulation packages. They will imbue your code not only with the ability to do date-comparison (for use with Perl's existing sort-capability), but also the ability to support any date-format. The heavy-lifting has been pushed out of our code and into the purpose-built CPAN routines. Needless to say, they solve the “Y2K problem” in industry-standard accepted ways. It all just works.

Honestly, with so many thousands of great routines out there, your first step in handling almost any problem is to figure out which ready-made solution you can pick off the shelf, whack-on just a few times to get it to do exactly what you want, then just drop-in and use... The fastest way to do any job is to not have to do it at all.

Replies are listed 'Best First'.
Re^2: Combining s///
by ack (Deacon) on Mar 10, 2008 at 20:31 UTC

    Globally, I agree with sundialsvc4 and would strongly encourage following the good monk's advice.

    However, it's hard to beat the simplicity and compactness of starbolin and ikegami's approaches. Saves loading the CPAN modules and, for those like myself who can't use CPAN modules on our control systems, it is sometimes the only way (Don't get me started on why we can't you use CPAN modules...it's a sore point with me that our IT-Nazi's impose such restrictions).

    Plus, the provided solutions teach a lot about the oft-misunderstood regexes and the regex engine.

    I really liked starbolin's and ikegami's compact solution. I had tried to do the same thing, but couldn't figure out how to get the Perl code into the substitution portion of the s/// regex. Thanks, starbolin and ikegami.

    ack Albuquerque, NM