TorontoJim has asked for the wisdom of the Perl Monks concerning the following question:
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:
I can call it without issue like this:sub exists { ... blah ... }
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Override built-in functions?
by LanX (Saint) on Dec 15, 2020 at 12:29 UTC | |
by choroba (Cardinal) on Dec 15, 2020 at 12:59 UTC | |
by TorontoJim (Beadle) on Dec 15, 2020 at 14:07 UTC |