3 ms·
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 tha
by hnu0847 5y 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?
- jwilk 5y agoA sub without prototype (anonymous or not) indeed allows any number of arguments. That's sufficient to trigger the syntax error.
- hnu0847 5y agoSo 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?
- jwilk 5y agoThat's right.