Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

parser bug handling 'do ($foo)->{bar}' ?

by LanX (Saint)
on Oct 14, 2014 at 13:31 UTC ( [id://1103737]=perlquestion: print w/replies, xml ) Need Help??

LanX has asked for the wisdom of the Perl Monks concerning the following question:

Hi

Does it make sense that

do ($foo)->{bar}

is parsed like

do ($foo ->{bar} )

instead of

(do $foo )->{bar}

or is it rather a bug?

Please compare how different

eval ($foo)->{bar}

gets parsed (see Re^2: B::Deparse weirdness (parser weirdness!) )

I understand that "Only Perl can parse Perl" but I think in order to secure the future of the language we should find ways to fix such inconsistencies.

Think about the problems for projects like Perlito or PPI.

Maybe more a meditation, hoping for more insights and a productive discussion.

Cheers Rolf

(addicted to the Perl Programming Language and ☆☆☆☆ :)

update

Are there more built-ins like this?

Do they qualify as unary operator (that's the way B::Deparse) tries to handle them.)

Isn't the precedence of unop well defined?

Replies are listed 'Best First'.
Re: parser bug handling 'do ($foo)->{bar}' ?
by Eily (Monsignor) on Oct 14, 2014 at 14:02 UTC

    I guess this comes from the fact that do is also used for flow control, which means it doesn't fall under the "Looks like a function" rule. print "Hello" if(0) || 1; prints "Hello", because if is not a function.

    This behaviour is actually documented for last and its kind:

    It is also exempt from the looks-like-a-function rule, so last ("foo")."bar" will cause "bar" to be part of the argument to last.
    Maybe the documentation for do should mention the same thing.

      Thanks a lot that makes things a bit clearer. :)

      But could you explain how do FILE which does per definition an eval is more a flow control than just eval ?

      update

      Not to mention that flow control statements don't return values. (maybe with the exception of short circuiting expressions)

      Cheers Rolf

      (addicted to the Perl Programming Language and ☆☆☆☆ :)

        My answer starts by "I guess", so you have to take it for what it is. do FILE; is kinda like goto FILE; except it works. Like goto, do has two different meanings depending on the syntax, and the flow-control side means the keywords are not parsed like most other.

        Edit: I'm not saying that do is always flow control, but that since it may be, the parser deals with it differently

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2024-04-19 20:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found