Category Archives: subroutines

Enchant closures for better debugging output

When you’re using code references heavily, you’re going to have a problem figuring out which one of them is having a problem. You define them in possibly several and far-flung parts of your program, but when it comes to using them, you don’t know which one you are using. You can’t really print its value […]

Make your methods know as little as possible

How often have you wished that one of Perl’s modules did things slightly differently? That module mostly works for you except for some hard-coded decisions in string formats, pack specifications, or other minor point that you wish that you could configure.

Eliminate needless loops and branching

On Stackoverflow, there’s the question How can I convert a number to its multiple form in Perl?. The best answer for the particular problem is Number::Bytes::Human. Beyond, that, many of the answers take the usual if-elsif-else, such as the one suggested by Michael Cramer: