Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re^3: why does Perl eval have a strange terminator?

by ikegami (Patriarch)
on Jun 14, 2022 at 20:55 UTC ( [id://11144738]=note: print w/replies, xml ) Need Help??


in reply to Re^2: why does Perl eval have a strange terminator?
in thread why does Perl eval have a strange terminator?

I suppose I didn't understand that a simple statement can be, the same time BE a compound statement

Something is either a simple statement or a compound statement, not both.

But one can include the other.

  • eval { for (1..2) { f(); } }; is a simple statement.
  • for (1..2) { f(); } is a compound statement.
  • f(); is a simple statement.

And eval is neither a simple nor a compound statement. As I've already said, eval is an operator (like +, and and time), not a type of statement.

Operators can include blocks and thus statements:

  • do
  • eval
  • map
  • grep
  • sort
  • print (e.g. print { ; $fh } $_)
  • say
  • Subs calls to subs with the & prototype
  • Indirect method call (e.g. new { ; "Class" })
  • Replacement "expression" of s///e
  • Circumfix derefs (e.g. ${ ; \$_ })
  • (?{ }) in regex patterns
  • (??{ }) in regex patterns

Replies are listed 'Best First'.
Re^4: why does Perl eval have a strange terminator?
by perlfan (Vicar) on Jun 24, 2022 at 20:11 UTC
    Try::Tiny requires a ;, and if you investigate why it is because it is implemented using prototypes.
    sub try (&;@) { ... sub catch (&;@) { ... sub finally (&;@) { ...
    I am not suggesting "eval BLOCK" is implemented using prototypes, but one could implement their own that would literally become a drop-in replacement (since the ; is likey already there. FWIW, (&;@) means the BLOCK param is coerced into a coderef, then optionally (after that ;), which allows something like the:
    try { } catch { } finally { };
    So now the POD seems to make a little more sense.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11144738]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (5)
As of 2024-03-28 16:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found