I'm asking as a point of learning here. I have a simple module that takes a key/value pair, stores it, then lets the user access it. Basically, a hash but as a module. Why? Just so I can try different things out.
The question is about naming methods in the module the same as Perl's built-in functions. For example, since I am storing key/value pairs I want to know if a key exists. Perl has a built-in function exists() and has to be called on an array or hash, e.g. exists(foo[0])
That name "exists" is the perfect description of what I want to do with this module. So if I write in the module:
sub exists {
... blah ...
}
I can call it without issue like this:
use MyPackage;
my $obj = MyPackage->new();
$obj->set_value('foo', 'bar');
if($obj->exists('foo')) {
print "that key is there\n";
}
It works just fine. So I want to know why I'm able to override the built-in function? Is it because the procedure I'm writing is always called by the object handle? Does that make it NOT the same as the built-in function?
Just trying to understand how it works
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.