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
- 达芙的设备
- 可移植性和标准性
- 用空格分隔列表和字符串的行情
- 可别名的命名空间
- 静电诱剂
- 职能是头等舱公民
- 阻止作用域和关闭
- 通过变量间接调用方法和访问器
- 通过代码定义方法
- 无所不在的在线文档
- 魔术方法
- 符号参考
- 交换一行价值
- 能够用您自己的功能替换甚至核心功能
操作员:
- 布尔准算子
- 触发器运算符
- 还用于列表构建
- The bool quasi-operator
- The flip-flop operator
- Also used for list construction
引用结构:
- The qw operator
- Letters can be used as quote delimiters in q{}-like constructs
- Quoting mechanisms
语法和名称:
- There can be a space after a sigil
- You can give subs numeric names with symbolic references
- Legal trailing commas
- Grouped Integer Literals
- hash slices
- Populating keys of a hash from an array
模块,实用程序和命令行选项:
Modules, Pragmas, and command-line options:
- use strict and use warnings
- Taint checking
- Esoteric use of -n and -p
- CPAN
overload::constant
- IO::Handle module
- Safe compartments
- Attributes
变量:
- Autovivification
- The
$[
variable - tie
- Dynamic Scoping
- Variable swapping with a single statement
回路和流量控制:
- 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
其他技巧和元答案:
- cat files, decompressing gzips if needed
- Perl Tips
另请参见:
- Hidden features of C
- Hidden features of C#
- Hidden features of C++
- Hidden features of Java
- Hidden features of JavaScript
- Hidden features of Ruby
- Hidden features of PHP
- Hidden features of Python
- Hidden features of Clojure
推荐答案
通过魔术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;
(处理带外壳元字符的文件名时,必须在$ _前后加上引号)
现在
<>
功能将解压缩以".gz"或".Z"结尾的所有@ARGV
文件:Now the
<>
feature will decompress any@ARGV
files that end with ".gz" or ".Z":while (<>) { print; }
这篇关于Perl的隐藏功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文