in reply to why does Perl eval have a strange terminator?
«if», «else» and «while» are keywords part of "if" statements and "while" statements. Flow control statements don't take semicolons.
while ( COND ) BLOCK if ( COND ) BLOCK
The «if» and «while» keywords are also found in statement modifiers. Statements with statement modifiers do take a semicolon.[1]
EXPR while COND; EXPR if COND;
eval and map are "functions" (named operators). Function calls do no take semicolons.
But they may be found in statements which do use a semicolon.if ( !eval { f() } ) { ... }
my $x = eval { f() } or ...;
This includes simple statements.[1] These are statements that consist of nothing but an expression.
EXPR;
The statement you gave is an example of a simple statement, and so is the «or»-using statement above.
C, C++, C#, JavaScript and Java all work this way.
Updated to elaborate.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: why does Perl eval have a strange terminator?
by misterperl (Friar) on Jun 14, 2022 at 20:04 UTC | |
by haukex (Archbishop) on Jun 14, 2022 at 20:26 UTC | |
by ikegami (Patriarch) on Jun 14, 2022 at 20:55 UTC | |
by perlfan (Parson) on Jun 24, 2022 at 20:11 UTC | |
by LanX (Saint) on Jun 14, 2022 at 21:56 UTC | |
by ikegami (Patriarch) on Jun 27, 2022 at 13:29 UTC |