Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: why does Perl eval have a strange terminator?

by LanX (Saint)
on Jun 14, 2022 at 15:30 UTC ( [id://11144729]=note: print w/replies, xml ) Need Help??


in reply to why does Perl eval have a strange terminator?

That's how the parser is organized.

you must distinguish between

(Contrived) Examples:

map and eval fall into the function category.

  • @x = map { $_ ** 2  } @y ;

    you can see multiple nested terms and functions in the statement

  • for ( eval{ some_func() } ) { print }

    for (EXPR) {BLOCK} is a compound statement and eval is single EXPR without(!) semicolon

NB: If you wanted to use a compound statement inside an expression, you would need to put it inside do {BLOCK}

HTH! :)

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery

updates

  • added links to simple-statements, terms and expressions
  • PS: It's a bit confusing that Larry's definition of "Term" (leaf of the syntax-tree) is different to the one in mathematics.
  • Log In?
    Username:
    Password:

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

    How do I use this?Last hourOther CB clients
    Other Users?
    Others romping around the Monastery: (5)
    As of 2024-04-19 05:21 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      No recent polls found