"John W. Krahn" <[EMAIL PROTECTED]> wrote:
>On Friday 01 February 2002 02:26, Bart Lateur wrote:
>>
>>      $date =~ s{(\d+)/(\d+)/(\d+)}{sprintf '%02d/%02d/%d', $1, $2, $3}e;
>
>       $date = sprintf '%02d/%02d/%d', $date =~ m|(\d+)/(\d+)/(\d+)|;

That's very different.  Bart's doesn't translate if $date doesn't
match.  John's translates it to 00/00/0. Bart's leaves alone
extraneous leading and trailing characters.  John's strips them.

How about:

$date =~ s<^(\d+)/(\d+)/(-?\d+)\z>{ sprintf '%02d/%02d/%d', $1, $2, $3 }e;

I suspect Michael Schwern of suggesting the combination of s///e and
sprintf out of sarcasm, but s///e really does match the general
problem of if ($x =~ $re) { $x = f($x) } (or even
if ($x =~ $re) { $x = f($x) } else { error... } very well.

Though I really liked Ala's:

s|\b\d/|0$&|g

(translated into English: repeated B&D leads to emptiness.)

Reply via email to