muthuvel_perl has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks,
How overriding concepts works in perl?
Anyone can explain how it works and also explain with some examples.
I can't get clear about this concepts when i was search in books and site.
Thanks in advance
Muthuvel

Replies are listed 'Best First'.
Re: Overriding Concepts in Perl.
by Zaxo (Archbishop) on Jun 27, 2005 at 06:10 UTC

    Overriding builtins, functions or object methods means defining subs which replace them at runtime. Overloading is a related, overlapping, concept for operators and methods which it is enlightening to compare.

    See perlsub, perldata on typeglobs, the perlobj family of docs, and the overload pragma. That is nowhere near an exhaustive list. You'll know a lot when you get comfortable with this question.

    After Compline,
    Zaxo

Re: Overriding Concepts in Perl.
by Adrade (Pilgrim) on Jun 27, 2005 at 06:08 UTC
    Perhaps you're inquiring about overloaded operators. This you can do using the overload package. You can read about it here, here and here .

    Hope this helps a bit,
      -Adam

    --
    Impossible! The Remonster can only be killed by stabbing him in the heart with the ancient bone saber of Zumakalis!

Re: Overriding Concepts in Perl.
by davido (Cardinal) on Jun 27, 2005 at 05:53 UTC

    What do you wish to override?


    Dave

Re: Overriding Concepts in Perl.
by Joost (Canon) on Jun 27, 2005 at 09:25 UTC
Re: Overriding Concepts in Perl.
by dave_the_m (Monsignor) on Jun 27, 2005 at 15:19 UTC
    You can override concepts like this:
    use override qw(concept1 concept2 ...);

    Dave.

Re: Overriding Concepts in Perl.
by ikegami (Patriarch) on Jun 27, 2005 at 19:22 UTC

    Does this help?

    package Base; sub new { my ($class) = @_; return bless({}, $class); } sub method { print("Base.\n") } package Child; our @ISA = 'Base'; sub method { print("Child!\n") } package main; my $o; $o = Base->new(); $o->method(); $o = Child->new(); $o->method();