TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

10 tips for writing perl one-liners

64 点作者 nelhage大约 15 年前

8 条评论

jrockway大约 15 年前
Perl is dead. One-liners are unmaintainable. Everyone should write their one-off command invocations with test driven development, separation of interface and implementation, javadoc, and aspect-oriented programming.
评论 #1384231 未加载
评论 #1384240 未加载
评论 #1385031 未加载
pkrumins大约 15 年前
Also see my article on "Perl One-Liners Explained":<p><a href="http://www.catonmat.net/blog/perl-one-liners-explained-part-one/" rel="nofollow">http://www.catonmat.net/blog/perl-one-liners-explained-part-...</a>
评论 #1384617 未加载
devinj大约 15 年前
I think this article has convinced me that I should learn Perl. Looks bloody useful for shell scripts, indeed ("a better awk" is the phrasing I've heard).
评论 #1384235 未加载
评论 #1384953 未加载
评论 #1384411 未加载
d0mine大约 15 年前
`END{ }` could be replace by eskimo operator `}{`:<p><pre><code> perl -F, -lane '$t += $F[1]; }{ print $t' </code></pre> <a href="http://www.perlfoundation.org/perl5/index.cgi?eskimo_operator" rel="nofollow">http://www.perlfoundation.org/perl5/index.cgi?eskimo_operato...</a><p>`..` is called flip-flop in the context describe in the post.<p>Goatse operator `=()=`:<p><pre><code> my $count_vowels =()= /[aeiou]/g; </code></pre> Here's another usage for `\K`:<p><pre><code> echo '/a/b/c/def/gh' | perl -lnE'$d{$`}++while/\w\K\b/g }{$,=" ";say keys%d' </code></pre> Output:<p><pre><code> /a/b/c/def/gh /a/b/c /a/b/c/def /a/b /a </code></pre> <a href="http://stackoverflow.com/questions/2892126/file-fix-it-codegolf-gcj-2010-1b-a/2894170#2894170" rel="nofollow">http://stackoverflow.com/questions/2892126/file-fix-it-codeg...</a><p>Other features: <a href="http://stackoverflow.com/questions/161872/hidden-features-of-perl/" rel="nofollow">http://stackoverflow.com/questions/161872/hidden-features-of...</a>
vtail大约 15 年前
Tricks 1-7 are also supported by Ruby - it accepts the same command-line options with the same functionality.
telemachos大约 15 年前
A good collection of articles, tutorials and slide-shows on Perl one-liners, all in one place:<p><a href="http://bufferfly.members.winisp.net/Perl_oneLiners.html" rel="nofollow">http://bufferfly.members.winisp.net/Perl_oneLiners.html</a><p>(I remember especially liking the one from Sial.org - a lot of good Perl content on that site, the two from Cultured Perl and the FMTYEWTK on mass edits.)
chrismealy大约 15 年前
I didn't know about \K and -MRegexp::Common. I liked the explanation of '..' too. Thanks.
absconditus大约 15 年前
See also:<p><a href="http://petdance.com/perl/command-line-options.pdf" rel="nofollow">http://petdance.com/perl/command-line-options.pdf</a>