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.

Perl: When DWIM Doesn't

27 pointsby douglashunterover 13 years ago

6 comments

draegtunover 13 years ago
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 未加载
vetlerover 13 years ago
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 未加载
joeyhover 13 years ago
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 未加载
pavelkaroukinover 13 years ago
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 未加载
hirojinover 13 years ago
<p><pre><code> use strict; use warnings;</code></pre>
评论 #3534231 未加载
aiurtouristover 13 years ago
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 未加载