开发者

What is the post-for/if syntax called?

Does the following syntax have a name?

print for ( @ARG开发者_如何学JAVAV );

exit if $x;


They're statement modifiers.


It's called "Statement Modifiers" in the perlsyn documentation.


Sometimes they are known as postfix constructions.


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.

for ( @ARGV ){
    print;
}

if ($x) {
    exit;
}

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

print for ( @ARGV );

exit if $x;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜