|more useful options|
Re: $obj->method v.s. $obj->method()by moritz (Cardinal)
|on May 09, 2009 at 11:05 UTC||Need Help??|
There are tools in Perl that allow you to find things like that out by yourself.
The first and easiest (but perhaps not always the most precise) is B::Deparse, which lets perl parse the program, and then reconstructs it from its internal representation. Let's try that:
So B::Deparse thinks the two are equivalent.
If you don't trust that, you can get an output of the internal representation of Perl, which is called its op tree with B::Concise:
You don't have to understand its output (neither do I, although I see some sense in some of it), but you can simply compare the two outputs:
(Don't compare them without a tool, it's too easy to miss a small difference in 2x 8 lines of weird symbols).
So you see that both forms construct the same op tree.
(You don't have to understand the rest of the post, if it confuses you just ignore it).
That said, it's still no 100% proof, because the presence of the parenthesis might affect the parsing of the next term. To check that, you could try the same with
If the parser expects a term, the /.../ part will be parsed as a regexp, if it expects an operator it will parse the slash as the division operator, and the # takes care that the last slash isn't a syntax error. (Yes, I checked it; no, the parens don't make a difference).