Perl 的隐藏功能? [英] Hidden features of Perl?
本文介绍了Perl 的隐藏功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在 Perl 中有哪些真正有用但深奥的语言特性,您实际上可以用来做有用的工作?
What are some really useful but esoteric language features in Perl that you've actually been able to employ to do useful work?
指南:
- 尽量将答案限制在 Perl 核心而不是 CPAN
- 请举例并简要说明
(这些都来自 Corion 的回答)
- C
- 达夫的装置
- 便携性和标准性
- 空格分隔列表和字符串的引号
- 可别名命名空间
- 静态初始化器
- 函数是一等公民
- 块作用域和闭包
- 通过变量间接调用方法和访问器
- 通过代码定义方法
- 无处不在的在线文档
- 神奇的方法
- 符号引用
- 一行值交换
- 能够用您自己的功能替换甚至核心功能
运营商:
- bool 准运算符
- 触发器运算符
- 也用于列表构建
引用结构:
语法和名称:
模块、编译指示和命令行选项:
Modules, Pragmas, and command-line options:
变量:
循环和流量控制:
- Magic goto
for
on a single variable- continue clause
- Desperation mode
正则表达式:
- The
G
anchor (?{})
and '(??{})` in regexes
其他功能:
- The debugger
- Special code blocks such as BEGIN, CHECK, and END
- The
DATA
block - New Block Operations
- Source Filters
- Signal Hooks
- map (twice)
- Wrapping built-in functions
- The
eof
function - The
dbmopen
function - Turning warnings into errors
其他技巧和元答案:
另见:
推荐答案
通过 magic ARGV 添加对压缩文件的支持:
Add support for compressed files via magic ARGV:
s{ ^ # make sure to get whole filename ( [^'] + # at least one non-quote . # extension dot (?: # now either suffix gz | Z ) ) z # through the end }{gzcat '$1' |}xs for @ARGV;
(处理带有 shell 元字符的文件名所必需的 $_ 周围的引号)
现在
<>
功能将解压缩任何以.gz"或.Z"结尾的@ARGV
文件:Now the
<>
feature will decompress any@ARGV
files that end with ".gz" or ".Z":while (<>) { print; }
这篇关于Perl 的隐藏功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文