是否有理由在 Perl 中使用 open(...) 的双参数形式?

编程入门 行业动态 更新时间:2024-10-22 21:38:54
本文介绍了是否有理由在 Perl 中使用 open(...) 的双参数形式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

是否有任何理由在 Perl 中使用 open(...) 的两个参数形式而不是三个或更多参数的版本?

Are there any reasons to ever use the two-argument form of open(...) in Perl rather than the three-or-more-argument versions?

我能想到的唯一原因是显而易见的观察结果,即双参数形式更短.但是假设冗长不是问题,是否还有其他原因让您选择 open(...) 的双参数形式?

The only reason I can come up with is the obvious observation that the two-argument form is shorter. But assuming that verbosity is not an issue, are there any other reasons that would make you choose the two-argument form of open(...)?

推荐答案

One-and two-arg open 应用任何由 -C 开关或 open 指定的默认层语用.三 arg 打开没有.在我看来,这种功能差异是选择其中一个的最有力的理由(选择会因您打开的内容而异).哪个是最简单或最具描述性或最安全"的(您可以安全地使用带有任意文件名的两个参数 open,它只是不方便)在模块代码中退居次席;在脚本代码中,您可以更自由地选择是否支持默认图层.

One- and two-arg open applies any default layers specified with the -C switch or open pragma. Three-arg open does not. In my opinion, this functional difference is the strongest reason to choose one or the other (and the choice will vary depending what you are opening). Which is easiest or most descriptive or "safest" (you can safely use two-arg open with arbitrary filenames, it's just not as convenient) take a back seat in module code; in script code you have more discretion to choose whether you will support default layers or not.

此外,Damian Conway 的文件 slurp 运算符需要单参数打开

Also, one-arg open is needed for Damian Conway's file slurp operator

$_ = "filename"; $contents = readline!open(!((*{!$_},$/)=\$_));

更多推荐

是否有理由在 Perl 中使用 open(...) 的双参数形式?

本文发布于:2023-11-29 08:33:41,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1645882.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:有理由   形式   参数   open   Perl

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!