5

Does the following syntax have a name?

print for ( @ARGV );

exit if $x;
Tim
  • 13,904
  • 10
  • 69
  • 101

4 Answers4

7

They're statement modifiers.

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
4

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

Mat
  • 202,337
  • 40
  • 393
  • 406
1

Sometimes they are known as postfix constructions.

mob
  • 117,087
  • 18
  • 149
  • 283
0

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;
MacMartin
  • 2,366
  • 1
  • 24
  • 27