Archive for the ‘Perl’ Category

PBP: 079 Tabular Ternaries

Thursday, January 29th, 2015

Mr. Conway suggests that you can cascade uses of the ternary (?:) operator instead of an if-elsif-else chain.  He feels this is much more readable.  I strongly disagree. (more…)

PBP: 078 Value Switches

Monday, January 26th, 2015

The idea behind this Best Practice is to explain how a table lookup can be used instead of an if/elsif/elsif/elsif/elsif/else block to make selections from a set of constants.  This is almost always a good choice! (more…)

PBP: 077 Multipart Selections

Thursday, January 22nd, 2015

The PBP say “Avoid cascading an if.”  At first glance, this sounds like a pretty harsh suggestion.  As it turns out, I rarely ever have any issue following this suggestion.  Well organized code seems not to need long if/elsif/elsif/elsif/elsif/else blocks. (more…)

PBP: 076 List Processing Side Effects

Monday, January 19th, 2015

Mr. Conway suggests the very firm, “Never modify $_ in a list function.”  I’m torn on this. (more…)

PBP: 075 Complex Mappings

Thursday, January 15th, 2015

The PBP suggests we factor complex map blocks into subroutines.  Please, please do this! (more…)

PBP: 074 List Transformation

Monday, January 12th, 2015

The last Best Practice suggested using map instead of a for loop to process lists.  There is an exception suggested by the Best Practices; if you’re transforming a list in place, use a for loop. (more…)

PBP: 073 List Selections

Thursday, January 8th, 2015

The Best Practice is to use grep and first instead of for to refine or search lists.  Again, there are good reasons, but I find it difficult, and am only improving with deliberate practice. (more…)

PBP: 072 List Generation

Monday, January 5th, 2015

The Best Practice is to use map when generating a new list from an old one.  The reasoning is good, but I struggle with it anyway.  I’m getting better with effort. (more…)

PBP: 071 Non-Lexical Loop Iterators

Thursday, January 1st, 2015

The statement made by this Best Practice is simple, “Always declare a for loop iterator with my.”  The reasoning behind it is complex, and surprised me.  I am sure I have screwed this up in the past, too.  It’s important as there’s a real gotcha here! (more…)

PBP: 070 Iterator Variables

Monday, December 29th, 2014

Mr. Conway suggests that you give explicit names for all for loops, and avoid the possibly confusing use of $_.  To this I say: Hallelujah! (more…)