加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

隐藏的Perl特性?

发布时间:2020-12-15 21:29:54 所属栏目:大数据 来源:网络整理
导读:在Perl中有什么真正有用但深奥的语言特性,你实际上可以用来做有用的工作? 指南: 尝试限制对Perl核心的答案,而不是CPAN 请给出一个例子和一个简短的描述 隐藏的功能也发现在其他语言的隐藏的功能: (这些都是从Corion’s answer) C Duff的设备 便携性和标
在Perl中有什么真正有用但深奥的语言特性,你实际上可以用来做有用的工作?

指南:

>尝试限制对Perl核心的答案,而不是CPAN
>请给出一个例子和一个简短的描述

隐藏的功能也发现在其他语言的隐藏的功能:

(这些都是从Corion’s answer)

> C

> Duff的设备
>便携性和标准性

> C#

>引号用于空格分隔的列表和字符串
>可别名命名空间

> Java

>静电助剂

> JavaScript

>职能是头等公民
>块范围和关闭
>通过变量间接调用方法和访问器

> Ruby

>通过代码定义方法

> PHP

>全面的在线文档
>魔法方法
>符号引用

> Python

>一行值交换
>能够用您自己的功能来替换核心功能

其他隐藏功能:

运算符:

> The bool quasi-operator
> The flip-flop operator

>也用于list construction

> The ++ and unary - operators work on strings
> The repetition operator
> The spaceship operator
> The || operator (and // operator) to select from a set of choices
> The diamond operator
> Special cases of the m// operator
> The tilde-tilde “operator”

报价结构:

> 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

模块,编译指示和命令行选项:

> 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

解决方法

触发器操作符在循环通过文件句柄返回的记录(通常为行)时跳过第一次迭代是有用的,而不使用标志变量:
while(<$fh>)
{
  next if 1..1; # skip first record
  ...
}

运行perldoc perlop并搜索“flip-flop”获取更多信息和示例。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读