post-for/if 语法称为什么?
以下语法有名称吗?
print for ( @ARGV );
exit if $x;
Does the following syntax have a name?
print for ( @ARGV );
exit if $x;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
它们是语句修饰符。
They're statement modifiers.
它在 perlsyn 文档中称为“语句修饰符”。
It's called "Statement Modifiers" in the perlsyn documentation.
有时它们被称为 postfix 建筑。
Sometimes they are known as postfix constructions.
如果您指的是代码片段的组成部分,是的,这些是语句修饰符。
如果您指的是语句的构造,我会说如下:
前置条件/前缀构造:
...条件(if $x)写在语句( { ... exit ...;})
这是编写这些语句的正常(最常用)方式。
后置条件/后缀构造:
... 条件(如果 $x ) 写在语句 ( { ... exit ...;}) 之后(发布)
这是反过来说。主要是为了走捷径,或者说一句台词。
有些人发现它很有用,但通常不鼓励这样做,因为可读性和理解性:请参阅 @mob 的回答
或者来自 PerlMonks:https://www.perlmonks.org/?node_id=177971
If you mean the the components of the snippet, yes, those are statement modifiers.
If you mean the construct of the statement I would say following:
pre-condition/prefix construct:
... the condition (if $x) is written before (pre) the statement ( { ... exit ...;})
It's the normal (most used) way to write those statements.
post-condition/postfix construct:
... the condition (if $x) is written after (post) the statement ( { ... exit ...;})
It's the other way around. Mostly for shortcuts, or one-liners.
Some find it usefull, but it's generally discouraged because or readability and understanding: see @mob's answer
Or from PerlMonks: https://www.perlmonks.org/?node_id=177971