Perl的 IO 操作太繁琐了

Wayne posted @ Tue, 23 Oct 2012 13:52:28 +0000 in Argument , 2755 readers

看来看去,所有提到 Perl  IO操作的地方,都说要用 FILEHANDLE。每次都是 filehandle,用之前要绑定,用完了要解除,烦都烦死了。总共代码没几句,读一个文件就是两句,open一句close一句。读入之后还有个奇葩的 chomp…… 不明白当初设计这样的读取方式是何意。语法糖都这么多了,顺手就把这个换行给去了嘛,非得让人手动来一下。偏偏这个chomp还不返回截掉尾巴后的字符串,只返回截掉了几个。不爽不爽,真心不爽。

还有那个if 后置,既然这样设计了,为啥不到位点呢,直接把 if .... else 都给弄进去得了,比如 xxxxx if yyyyy or else zzzzzz。 那样写起来多流利。如果 or else 这样两个字合起来的不好做,那就搞一个 oresle 这样的嘛。xxx?yyyy : zzzzz 这样虽然也能用,但一看就是抄C的,而且一点也不自然。

如果让我设计 IO 操作的部分,我绝对会设法把 <$filename> 给弄成直接读取文件。现在这表达式给了从命名文件handle中读文件,简直让人吐血。既不容易记忆又没多少人用。反正我看到的大多还是沿用 BARE WORD那种大写字母当 filehandle的形式。至于那个 typeglob,更是捣乱。 <$hash{$file}> 这样就是 typeglob, <$file  > 这样也是typeglob,<$file>却是从名字句柄读文件,这存心就是挖坑让人跳啊。而且 $ 这符号实在是滥用了。 标量用这个,各种reference也用这个,filehandle也要用这个。虽然说后面这些都可以认为是标量,但标量跟标量毕竟是不同的啊,操作方式都不一样,你都凑一起,搞的好像类型很少的样子,掩耳盗铃么?

Avatar_small
依云 said:
Wed, 24 Oct 2012 04:05:58 +0000

用 Python 吧。唯一不能直接满足你的地方只是不能自动去掉从文件读入的换行符。

zaeneas said:
Wed, 24 Oct 2012 11:35:18 +0000

http://www.tizag.com/perlT/perlif.php
perl支持if else的呀....

Avatar_small
Wayne said:
Thu, 25 Oct 2012 00:51:37 +0000

额,它当然支持 if else。 我说的是当 if 后置的时候。比如说 say if defined 这种

Primary Result Rajsh said:
Sat, 03 Sep 2022 09:28:59 +0000

Here are the complete details about PSC Result 2022 Rajshahi Board or Division, and students you are at the correct location to check total PSC Exam GPA Grade marks 2022 with downloading of full mark sheet, Primary Result Rajshahi Division as per DPE announcement there are lacks of students participate in this year like previous years, and this year this number is reached up to 30 lacks from all divisions in the country. This year also the Primary School Certificate Examination has completed as per schedule for all divisions and those terminal exams are held without delay under Rajshahi education board functioning under DPE, now they are ready to announce PSC Result 2022 with Full Marksheet for all education boards in the country.


Login *


loading captcha image...
(type the code from the image)
or Ctrl+Enter