Archive for the ‘Perl Best Practices’ Category

PBP: 046 Fat Commas

Monday, October 6th, 2014

Perl has a weird but cool operator, the “fat comma”, written as =>.  It’s a comma, but with a special property that means a bareword on the left side is allowed.  They’re often used for initializing hashes without having to quote every hash key.

The PBP suggests reserving => for items that go together, or, as it says “for pairs”.  Name => value pairs, mostly.  These things are related to each other and => makes that visible.  (more…)

PBP: 045 Barewords

Thursday, October 2nd, 2014

Perl supports “barewords”, which are strings that just sit naked in your program.  If it isn’t parsable code, it’s a bareword.  The PBP says: Don’t.  I agree, as does ‘use strict’, which I always use. (more…)

PBP: 044 Heredoc Quoters

Monday, September 29th, 2014

The PBP suggests that all heredocs be explicitly and deliberately quoted.  When I first read this, I didn’t know you could do that!  It’s a great idea. (more…)

PBP: 043 Heredoc Terminators

Thursday, September 25th, 2014

Mr. Conway suggests making all heredoc terminators single uppercase identifiers which start with a standard prefix.  This is part of naming things regularly, and I support it. (more…)

PBP: 042 Heredoc Indentation

Monday, September 22nd, 2014

The Best Practices suggest that putting a heredoc in a deeply nested function looks funny because it has to be left-justified, and suggests creating a “theredoc” by writing a function that does nothing besides evaluate and return the heredoc. (more…)

PBP: 041 Here Documents

Thursday, September 18th, 2014

The PBP tells us to use here documents when a multi line string is too long.  It suggests two lines is long enough for a single string, and anything longer should be a here document. (more…)

PBP: 040 Multiline Strings

Monday, September 15th, 2014

The PBP suggests breaking your strings on any embedded newlines so they look in code something like they’ll look when output. (more…)

PBP: 039 Long Numbers

Thursday, September 11th, 2014

Great big numbers full of digits are hard to read and be sure they’re right, so the PBP suggest using the magic underscore in the numbers to spread them out and make them more readable. (more…)

PBP: 038 Leading Zeroes

Monday, September 8th, 2014

Best Practice: Don’t pad decimal numbers with leading zeroes. (more…)

PBP: 036 Escaped Characters

Thursday, September 4th, 2014

The PBP suggests using named escape characters instead of hardcoding ASCII values.  It has some reasonable examples, such as this: (more…)