but there is no real ambiguity in the first place, or is there?
Us humans can see the picture and deduce an intent to divide in this example, but it's not easy to write a program to do that. Perl decides when it sees the / whether the / is part of the argument list. Since / can start an argument list, Perl guesses it's part of the argument list. When it detects an error, Perl has no way of knowing if it's because the programmer screwed up the match operator or if it's because it guessed wrong. Of course, you could tell Perl the function takes no arguments.
sub func() { return 8 }
print func / 4; # 2
+ and - are also tricky tokens.
sub foo { return 8 }
print foo + 4; # 8
print foo(+4); # 8
print foo() + 4; # 12
sub bar() { return 8 }
print bar + 4; # 12
print bar() + 4; # 12
There are problems with using prototypes, however. You should look into that before using them.
As a programmer, you should know that omitting the parens leads to this type of problem and consider missing parens as the source of problems.
|