TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Clingy Lexicals: Closures in perl

25 pointsby f00li5hover 14 years ago

1 comment

jrockwayover 14 years ago
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 =&#62; 'bar', bar =&#62; '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.)
评论 #1891852 未加载
评论 #1891662 未加载