At Shaun's company, the fiscal month ends on the 18th. Nothing wrong with that, but there's plenty wrong with this Perl code that finds the most recent fiscal month-end:

my $date='0000-00-00';
my $dd = 1;
my $mm = 1;
while(substr($date,8,2) ne '18') {
    my $sel0="select date_format(date_sub(date_sub(now(),interval $dd day),interval $mm month),'%Y-%m-%d')";
    my $setup=$dbh->prepare($sel0);
    $setup->execute();
    ($date)=$setup->fetchrow_array();
    $setup->finish();
    ++$dd;
}

That lustrous gem queries the database to return yesterday's date, and then the day before that, and then the day before that, etc., until it finds a date string whose last two characters are "18".

When svn blame revealed the perpetrator, Shaun was surprised: his co-worker Frank had four years on him, and reguarly gave him a hard time for his WTF moments. When he asked Frank to walk him through his thinking, the senior dev didn't get defensive. Instead, he grew sheepish.

"Aw man," Frank said, "I thought for sure that routine would've been zapped by now. You're looking at my very first checkin, Shaun, when I knew about as much Perl as my grandmother. You need to understand, man, it's not entirely my fault: all our Perl references naturally order Database Functions before those for Dates..."

Shaun wasn't so sure he should let Frank off the hook, but it was Friday afternoon and he was feeling generous. He settled for sending Frank the following email:

TO: [email protected]
SUBJECT: LMGTFY

https://metacpan.org/module/DateTime#How-DateTime-Math-Works ;)

Have a good weekend,

Shaun
[Advertisement] BuildMaster allows you to create a self-service release management platform that allows different teams to manage their applications. Explore how!