If B inherits A, and B::foo isn't defined, but A::foo is, calling B::foo will fail. There's no such sub.
If you want Perl to act in an OO way, you should make a method call, not a sub call. Use B->foo, and A::foo will be called.
If you can't or won't, you're out of luck.
use strict;
use warnings;
$| = 1;
sub A::foo {print "This is A::foo\n"}
@B::ISA = qw /A/;
print "Calling B->foo(): "; B->foo();
print "Calling B::foo(): "; B::foo();
__END__
Calling B->foo(): This is A::foo
Calling B::foo(): Undefined subroutine &B::foo called at ...
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.