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

BEGIN { *write = \&A::write } # Doesn't work!
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:
# 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
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.

lodin


In reply to Re: redefining CORE:: names by lodin
in thread redefining CORE:: names by dk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.