in reply to Truly global subroutines - Auto-exporting symbols into all packages
Why all the confusion to avoid use Debug;? It's a bad idea.
If I'd want to do it, I'd just create the sub in the main namespace and use :: in front of the sub name to look into that namespace.
package Debug; sub ::dp { print "Moo!\n"; } package test; ::dp;
$ perl a.pl Moo!
If you're truly insane, you could take advantage of the fact that certain symbol default to the main namespace instead of the current namespace.
package main; sub _ { print "Foo!\n" } *% = sub { print "Bar!\n" }; package test; _(); &%();
$ perl a.pl Foo! Bar!
Basically, any of the special symbol that's allowed as one-character var names (see perlvar) is can be used that way.
The catch is that except for _, they're not normally allowed as identifiers. You'll need to use the &name(...) syntax to call them, and you'll need to assign to the glob to define them.
But that's a bad idea.
|
|---|