[EMAIL PROTECTED] wrote:
>
> Please show me some pointers towards dynamic binding concepts in perl.We
> have dynamic binding concepts in c++ and java.Like that how can I implement
> dynamic binding in perl.
> Thanks in advance,
Hi Visu.
Dynamic binding is implemented in Perl using the special @ISA ('is a') array.
The classic example is using the fact 'all dogs are animals'. I assume you
know the basics of Perl OO programming? In which case the code below shows
you the essential idea. Let us know if you need anything further.
HTH,
Rob
package Animal;
use strict;
sub new {
my $class = shift;
bless {}, $class; # Bless into the correct class
}
sub method1 {
my $this = shift;
:
}
sub method2 {
my $this = shift;
:
}
package Dog;
use strict;
our @ISA = 'Animal'; # Dog is a subclass of Animal
sub method2 {
my $this = shift;
:
}
package main;
use strict;
my $dog = new Dog; # Calls Animal::new but creates a 'Dog' object
$dog->method1(); # Calls Animal::method1
$dog->method2(); # Calls Dog::method2
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>