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

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.

Replies are listed 'Best First'.
Re^2: parser bug handling 'do ($foo)->{bar}' ?
by LanX (Saint) on Oct 14, 2014 at 14:12 UTC
    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

        We all are only guessing. ;)

        But asking enough questions might eventually lead to an answer! =)

        Never (modulo Alzheimer) heard of the "looks like function rule" , but Deparse mentions it.

        Grateful for deeper insight!

        Cheers a questioning mind

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

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

        From do EXPR

        Uses the value of EXPR as a filename and executes the contents of the file as a Perl script. do 'stat.pl'; is largely like eval `cat stat.pl`;

        hope you understand now why I have problems to see the diff to eval regarding flow control.

        Cheers Rolf

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