免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2038 | 回复: 6
打印 上一主题 下一主题

Ten ways Perl programmers mess up their lives [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-08-22 10:24 |只看该作者 |倒序浏览
我在effective perl里摘录下的,大家快对照自己看看吧


(10) They keep using Perl 4
         Perl 4 is dead. Long live Perl 5. If you are thinking of buying a CGI programming book, make sure
        it uses Perl 5. You don‘ want one that uses cgi-lib.pl, calls all its subroutines with the
        &func() syntax, and doesn’t tell you anything about all the wonderful Perl modules that have been
        written in the past half decade.

(9) They confuse list and scalar context
         Remember that operators work differently, sometimes very differently, depending on the context
        they’re used in.
         For example, ?¡ãBoolean?¡À contexts like the condition of a while loop are scalar. while (1..10)
        {?-} means something entirely different than foreach (1..10) {?-}
         Or the difference between my ($foo) = @bar and my $foo = @bar

(8) They don’t understand regular expressions
         You can’t write Perl effectively without understanding and using regular expressions

(7) They omit (too much) punctuation
         Leaving out semicolons, commas, closing quotes, and/or parentheses can produce very strange
        error messages, or sometimes silent misbehavior
         For example, don’t forget the semicolon after an eval block or anonymous sub
         Don’t omit parentheses around arguments of || (better, use or instead)

(6) They don’t read their error messages
         When a program dies, always look at the first error message and/or warning issued
         When you return to the program source code, go to the line number mentioned in the error
         The error in the code is either at or before that line?not after

(5) They write fragile programs
         Always check return status from open, opendir, and other system calls
         Avoid using relative paths and shell metacharacters in backticks, system/exec, and pipe opens
         Avoid using non-portable code when a module exists to do the same thing portably

(File::Basename, Cwd, etc.)

(4) They bite off too much at once
         Learn to write two- or three-line programs to test features
         Or use perl -e 'insert Perl code here', or use the debugger as a Perl shell

(3) They reinvent the wheel
         Have an ordinary CGI or network programming task? It’s in the CPAN
         Perl modules have been tested, used, and (usually) thoughtfully designed, too
         You can get a lot done in a half dozen lines of Perl, especially if they just run someone else’s code

(2) They don’t read the documentation
         Read the Perl man pages, especially perlfunc
         Use perldoc to read stuff your man command can’t see
         Read any (good) Perl books you can ?nd

(1) They don’t use strict or -w
         There is very little sympathy for a Perl programmer who has a problem that -w would have caught
         -w is a pain sometimes, but it will catch many, many, many careless errors
         use strict helps you write better-designed programs
         Okay if you don’t bother in programs a few lines long, but always use them both otherwise?
        especially when embarking on a big new project (denition of ?¡ãbig?¡À varies according to skill level
        :-)

[ 本帖最后由 hdc1112 于 2008-8-22 10:45 编辑 ]

论坛徽章:
0
2 [报告]
发表于 2008-08-22 10:25 |只看该作者
没排格式,看着费眼睛

论坛徽章:
0
3 [报告]
发表于 2008-08-22 10:46 |只看该作者
崩溃了,里面有些字符很奇怪。。

论坛徽章:
0
4 [报告]
发表于 2008-08-22 11:11 |只看该作者
我要改正改正

楼主可以时不时的发给这样的文章

这些算是perl rule,我们可以随时review一下,这对我们的编程很有好处

感谢分享

论坛徽章:
0
5 [报告]
发表于 2008-08-22 17:24 |只看该作者
学perl就得细心

论坛徽章:
0
6 [报告]
发表于 2008-08-22 17:25 |只看该作者

回复 #5 forlorngenius 的帖子

好像学什么语言都得细心。呵呵

论坛徽章:
0
7 [报告]
发表于 2008-08-23 12:27 |只看该作者
They reinvent the wheel  
They don’t read the documentation
They don’t use strict or -w
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP