[Purdue-pm] Why? Why? Why?

Dave Jacoby jacoby.david at gmail.com
Fri Apr 3 06:56:18 PDT 2020


>From code.

            $variable = sprintf("%02d", 0);

This of course sets $variable to '00'. But if that's what you need to do...

            $variable = 00;

Some may not have hit this -- I find new functions all the time -- but
sprintf() is a variant of printf(), which formats a variable. printf()
prints it, sprintf() returns it. in this case, "%02d" gives a zero-padded
two digit decimal number. perldoc -f sprintf for more documentation.

sprintf() is good for converting variables, but if you hardcoded 0, you can
hardcode '00'.

Clearly nobody involved in this code is on this list, but really, is there
any justification besides cargo-cult programming?

-- 
Dave Jacoby
jacoby.david at gmail.com

I deal with my software the way I treat my eldritch abomination:
 It's not human, it's not even alive in the natural sense.
 It's nightmare-born and nightmare-shaped, and nightmares don't die easy.
  -- @yenzie
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.pm.org/pipermail/purdue-pm/attachments/20200403/b626d59a/attachment.html>


More information about the Purdue-pm mailing list