pileofrogs didn't specify that it needs to be done at run-time. It would be my preference to resolve such issues at compile-time unless there is some feature of the final product that required deferral of the sub declaration until run-time.
It is good to make the difference clear, I guess, just in case the difference really matters to someone looking for a way to add a class method from outside the package scope. That's not really the question that was asked, since pileofrogs asked about adding a method to an object. In many cases adding a method to the class is just as good as adding it to the object instance, so no harm done from that little difference. It is, BTW, easy to add a non-method subroutine to the object's data structure when using hash-based objects, but that could create more confusion than it solves.
Just for kicks, I'll give you a link to Hubba Bubba®. It may not be where you got the words, but anyone who grew up chewing this Wrigley® product will recognize the name on sight.
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.