Hacker News new | ask | show | jobs
by hnu0847 1580 days ago
Why does the following expect arguments:

    : sub {};
Don't all perl subroutines allow any number of arguments (including 0) to be passed?

Does the fact that the above is an anonymous subroutine affect the answer to my question?

1 comments

A sub without prototype (anonymous or not) indeed allows any number of arguments. That's sufficient to trigger the syntax error.
So basically this:

    sub() {}
does not try to parse the /1;#/+ as an argument because the () indicates there are no arguments (although they could be explicitly included if f were called with (), whereas this:

    sub f {}
does try to parse the /1;#/+ as an argument because that's perl's behavior if () are omitted?
That's right.