LAI has asked for the wisdom of the Perl Monks concerning the following question:
I was reading through a pretty masterful bit of redirection in a recent obfu written by SarahM. (It really is quite nice; I recommend you check it out before reading the spoilers below) Something in it prompted me to wonder about the way perl deals with namespaces of packages, and I was a little confused. I knew what was happening, but I couldn't put my finger on why.
Here's the spoiler to the obfu: SarahM defined a sub q, and later used the builtin q to fool the reader into thinking she was using her own sub. So my question is: under what circumstances does the builtin q// get overridden (assuming one would want to do such a thing)? Is it possible to code the following so that a simple call of q("something") will execute main::q?
sub q { return "inside main sub q"; } print "Ambiguity gets us the builtin: \n"; print q("not in sub q"), "\n"; print "Let us be more specific: \n"; print main::q("this does not get printed"), "\n"; __END__ Ambiguity gets us the builtin: "not in sub q" Let us be more specific: inside main sub q
LAI
__END__
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: When do subs get overridden? (&)
by tye (Sage) on Apr 03, 2003 at 21:28 UTC | |
|
Re: When do subs get overridden?
by MrYoya (Monk) on Apr 03, 2003 at 21:34 UTC | |
|
Re: When do subs get overridden?
by Mr. Muskrat (Canon) on Apr 03, 2003 at 21:12 UTC | |
by LAI (Hermit) on Apr 03, 2003 at 21:29 UTC | |
|
Re: When do subs get overridden?
by dakkar (Hermit) on Apr 05, 2003 at 11:24 UTC |