in reply to Why is (keys ::) legal syntax?
In op.c there is specific code to allow for keys( bareword ) to be treated as keys( %bareword ). If you turn on warnings you will get: Hash %bareword missing the % in argument 1 of keys() which is how I found the code:
and this makes me think that this is for compatability to something prior to Perl4.case OA_HVREF: if (kid->op_type == OP_CONST && (kid->op_private & OPpCONST_BARE)) {
Add to this the long-standing habit of print( hello ) being the same as print( "hello" ) (other than the optional errors and warnings).
Add to that a patch that noted that Module->Method() can sometimes be interpretted as Module()->Method() (or was it only Method Module that had that problem?) and that added support for the syntax Module::->Method() (or was it Method Module::?). I suspect that this is what made print( hello:: ) the same as print( "hello" ).
So these (may) explain why keys( main ) and keys( main:: ) are the same as keys( %main ).
Also consider that %main:: didn't use to work. You used to have to do %{"main::"}. And print( :: ) is the same as print( "::" ). So it makes some quirky sense that keys( :: ) is the same as keys( %:: ) which is now the same as keys( %{"main::"} ).
- tye (those who don't know history are doomed to invent it)
|
|---|