You get all sorts of warnings when you compile the A and B packages. Mismatching prototypes, ambiguous calls, etc.
subs.pm doesn't do anything but put something in the code slot in the glob. The prototype mismatch is because subs assigns a subroutine with no prototype to &write and then you redefine that. If you do the glob assignment first (in a BEGIN block) and have the subs statement after the glob assignment, then everything works. I was intrigued by why subs does the trick with its glob assignment, but simplly having
didn't. I've boiled it down to that the assignment has to be done by some other package (not necessarily subs, e.g. Exporter). So this works:BEGIN { *write = \&A::write } # Doesn't work!
I have no idea why you have to switch package. I'd appreciate if someone could point me to any perldoc that explains this. I haven't found anything about it.# Perl 5.8.8 { package X; # I change to X and Y because B is taken. sub write (&) { print $_[0]->() } } { package Y; BEGIN { package Something::Else; *Y::write = \&X::write; } write { 'OK' }; } __END__ OK
lodin
In reply to Re: redefining CORE:: names
by lodin
in thread redefining CORE:: names
by dk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |