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

科技回声

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

GitHubTwitter

首页

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

资源链接

HackerNews API原版 HackerNewsNext.js

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

Perl: When DWIM Doesn't

27 点作者 douglashunter超过 13 年前

6 条评论

draegtun超过 13 年前
re: <i>open() creating temporary file if file arg is undef</i><p>Fortunately both IO::File (core module) &#38; Path::Class don't do this:<p><pre><code> use IO::File; my $fh = IO::File-&#62;new( $config-&#62;{file_path}, 'r' ) or die "can't open $config-&#62;{file_path}: $!"; use Path::Class qw&#60;file&#62;; my $fh = file( $config-&#62;{file_path} )-&#62;openr; </code></pre> Both above spot the undef gotcha. NB. And <i>-&#62;openr()</i> throws an exception.<p>ref: <a href="https://metacpan.org/module/IO::File" rel="nofollow">https://metacpan.org/module/IO::File</a> | <a href="https://metacpan.org/module/Path::Class" rel="nofollow">https://metacpan.org/module/Path::Class</a>
评论 #3534094 未加载
评论 #3546365 未加载
vetler超过 13 年前
Maybe they should use classes and objects instead of hashes. I.e.<p><pre><code> $session-&#62;ab_variation_overrides(); </code></pre> This would prevent them from mistyping ab_variation_overrides everywhere they need it... But of course, it's a lot easier to solve everything with hashes in Perl. Been there, done that!
评论 #3533845 未加载
评论 #3533751 未加载
评论 #3533649 未加载
joeyh超过 13 年前
I basically gave up on perl after discovering this:<p><pre><code> foo foreach @bar; sub foo { s/foo/bar/ print; } </code></pre> This clobbers the content of @bar due to mutating the $_ variable. Which is a useful feature. But imagine that foo, instead of directly mutating the value passed to it, calls into a complex set of other code. Now you have a bomb where working code can break in crazy ways if any of it gets changed to modify $_.<p>Having to audit code for this kind of thing is a real pain. I still maintain existing perl projects, but won't be starting any new ones.
评论 #3538882 未加载
评论 #3534364 未加载
评论 #3534554 未加载
评论 #3534922 未加载
pavelkaroukin超过 13 年前
Both OPs examples would be spotted by unit tests and finding actual bug after that is quite trivial.<p>So I agree, you can trigger some features unpredictably, but this just shows power behind tool and remind you to be well self-organized =)
评论 #3534503 未加载
hirojin超过 13 年前
<p><pre><code> use strict; use warnings;</code></pre>
评论 #3534231 未加载
aiurtourist超过 13 年前
I love Perl. I wrote it professionally for 10 years. I have great friends who still do. The community is full of smart, fantastic people.<p>Five years ago, however, I learned Python for a job and never looked back. In terms of programming languages they're practically the same thing. But Python is easier to read, easier to write, and easier to hire for. And stuff like this (dereferencing, "array context," worrying about how to create my objects) makes me sigh.<p>Perl, I love you, but I'm not looking back.<p>(apologies for the language flame war bait)
评论 #3534137 未加载