in reply to Does perl allow overriding a function in two different files(.pl)
Usually when the question is "Does Perl allow...", the answer is yes. But specifically demonstrating the implementation requires that both parties have a meeting of the minds on what is being discussed.
Does Perl allow you to override functions defined in other modules? Yes. Does it allow you to override functions defined as class or object methods? Yes, there are ways.
But I think the first step is for us all to be on the same page. The Perl way has evolved over the years into a pretty elaborate framework of packages and modules. For us to fully understand what you're asking, you would need to learn the basics of the Perl way first so that you can accurately identify for us what aspect of overriding functions in Perl you're discussing. And you would need those basics in place to understand the responses you get as well.
Once you've had a look at perlmod and perlobj, you may feel more comfortable with the principles and with the nomenclature of Perl's namespaces, modules, packages, and OO system. At that point we would come closer to a meaningful discussion.
There certainly are answers to your question, and we would love to help. I believe that spending an hour looking over the two documents I pointed you to is the best and most accurate help I can offer until our languages sync up sufficient to answer more specifically.
I can say that it really helps if you use Perl packages, and modules. Doing so defines namespaces, relationships of interaction, and dependencies. If you're using, say module A, and you have a function in A called do_it(), but you decide that you no longer want do_it() done the A way, you have many options. Several of those options include that you can literally attach a new function in Perl's symbol table for A with the name do_it(), or you can create a new function in your current symbol table named do_it() that masks A's do_it() unless you use the fully qualified name( A::do_it() ) or a reference to that function. If you're using an OO approach, some of that applies too, but you also have options for inheritance, where a B inherits from class A, and may in so doing keep some of A's functionality while overriding other functionality.
By learning Perl's object and module system, you can take advantage of the tools, practices, and understanding of the Perl community, which provides wonderful leverage. Clumping together a bunch of .pl files in a folder and somehow evaling them, doing them, or require-ing them in non-standard ways gives you a very short lever to work with, as there won't be a set of established knowledge and tools already in existence to help you through your problem.
So please do go ahead and take a moment with those documents linked to. And if you really grow an interest, pick up the O'Reilly book, "Intermediate Perl." Then you'll be well on your way.
Dave
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Does perl allow overriding a function in two different files(.pl)
by codewalker82 (Initiate) on Jul 15, 2011 at 19:31 UTC | |
by davido (Cardinal) on Jul 15, 2011 at 21:57 UTC |