在Perl核心中是否有任何东西可以自动从“<>"行中删除行.操作员? [英] Is there anything in core Perl to auto-chomp lines from "<>" operator?
问题描述
在进行Perl编码时,我的一个小烦恼是必须记住切掉从输入中读取的行.是的,经过多年的编码,记住这样做几乎是自动的,但仍然很烦人.
One of the minor annoyances I have when doing Perl coding is the necessity to remember to chomp a line that you read from input. Yeah, after years of coding it's nearly automatic to remember to do so, but STILL annoying.
Perl中是否存在任何实用程序,模块或其他任何东西(强烈推荐的Core模块),这些东西会自动压缩使用<>
运算符读取的每一行?
Is there any pragma, module or anything else in Perl (strongly preferred Core modules) that automatically chomps every line read using a <>
operator?
推荐答案
除了您已经提到的各种源代码过滤器之外,我怕在这里您不知道什么是"hack".您认为这些显而易见的解决方案中的任何一种都是骇客"吗?
Beyond the asquerous source filters that you already mentioned, I’m afraid I don’t know what counts as "a hack" for your purposes here. Do you consider any of these obviousish solutions to be "hacks"?
- 覆盖当前软件包中的
*CORE::readline
在所有程序包中 - 覆盖
*CORE::GLOBAL::readline
- 使用自定义的
READLINE
方法处理与类的联系 -
<>
运算符的运算符重载
- overriding
*CORE::readline
in the current package - overriding
*CORE::GLOBAL::readline
in all packages - handle ties to a class with a custom
READLINE
method - operator overloading of the
<>
operator
您尝试过这些吗?
在这些中,我认为第一个或第二个可能最有可能以最小的麻烦来做您想要的事情.
Of those, I would think the first, or possibly the second, to be the most likely to do what you want with the least amount of fuss.
请注意,所有这四个解决方案只需要纯Perl,就不需要其他任何东西.他们甚至不需要任何核心模块,更不用说任何CPAN模块了.
Note that all four of those solutions require nothing but pure Perl and nothing else. They do not even require any core modules, let alone any CPAN modules.
这篇关于在Perl核心中是否有任何东西可以自动从“<>"行中删除行.操作员?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!