in reply to ARGV as a sub name?

B::Deparse reveals all:

$ perl -MO=Deparse package foo; sub ARGV { print "in foo::ARGV\n" } package main; foo->ARGV; package foo; sub main::ARGV { print "in foo::ARGV\n"; } package main; 'foo'->ARGV; - syntax OK

I haven't yet found the part of the parser which forces sub ARGV into main::.

Replies are listed 'Best First'.
Re^2: ARGV as a sub name?
by james2vegas (Chaplain) on Aug 18, 2010 at 21:37 UTC
    Interestingly enough, if you add use strict (at least on 5.8.9 and 5.10.1) to package foo, B::Deparse does not reveal all, like so:
    package foo; sub BEGIN { require strict; do { 'strict'->import }; } sub ARGV { use strict 'refs'; print "in foo::ARGV\n"; } package main; use strict 'refs'; 'foo'->ARGV;
    (in fact just making sub ARGV not the first line of code after package foo is enough to confuse B::Depase in this.