There are two topics I refuse to blog about -- monads and how to indent Perl code. But HN doesn't count as a blog, so here is <i>jrockway's simple perl style guide</i>.<p>There is one rule: everything is a block. If you write a function, you write it like:<p><pre><code> sub foo {
my $code = 'goes here';
}
</code></pre>
Now do this for everything:<p><pre><code> my %hash = (
foo => 'bar',
bar => 'baz',
);
my $coderef = sub {
my $hey_just_like_a_normal_sub;
return sub {
"OH HAI"
};
};
</code></pre>
If you can condense something onto one line, then do it:<p><pre><code> my @foos = grep { /foo/ } @stuff;
my $coderef = sub { 42 };
</code></pre>
This is the most widely-used style, and it's something everyone should do to be consistent with everyone else. The only time I have ever seen anything else is in this blog post.<p>(Okay, cperl-mode does it wrong by default. I changed it a few years ago and got immediate hate mail. I'm pretty sure there is some script out there that checks out cperl-mode from git, indents some code with it, and sends email if the indentation is not exactly the same as it was in 1993. The script also adds random words from /usr/share/dict/words, and that wordlist only contains various spellings of "fuck". Apparently.)