in reply to The Behavior of 'do'
Even more curiously, do 4; produces 1 as a result with nothing in any of the error variables, as opposed to do '4'; which looks for a file. Ditto for do 2+2 which makes me think that a numeric value is being treated differently. I don't even know what it's doing! Could it be a bug, due to common code in the implementation with use and require, which indeed mean something different with numbers? Update: yes, it is doing exactly that.
As for barewords, others like do shift; is looking at is as a string, not a function, too.
My guess is that, contrary to the documentation, a bareword to do is always treated as a string (even under use strict and use warnings!) like with use.
You may want to try and see if it replaces :: with slash, like require does. It's not assuming the extension, so maybe not. But it sounds like what's happening is do/require/use is implementing some functionality at the do level, or the compiler has more in common with them than is documented.
Hopefully, a perl porter will investigate this further. I agree, it is not behaving as documented in perlfunc and perldata. My guess: common handling with use/do/require in the parser. I'd say document the "always a string", and fix the numeric context behavior to take it as a string (it's pointless to duplicate require).
Now, for the parens: That makes it a list. In scalar context, it gives the item count. Anything that's not a bareword is treated as a normal expression, and if non-numeric, the result of the expression names the file. —John
|
|---|