My question is, shouldn't there be a third file (one that's named say main.pl ?For the purposes of demonstration, seperating the packages into seperate files isn't necessary, or even seperating the 'main' code for that matter. However, if you want to use the packages One and Two you will need to save them as a .pm files in the library path. As for the 'main' section of code, that could be saved to a file, or piped into STDIN or even in as commandline argument to -e. As ever TIMTOWTDI :)
What difference does '@ISA = ("One");' in Two.pm make?It means that any subroutines in One are inherited by Two (which wasn't demonstrated in your example) e.g
So as you can see from the output Two has inherited One's methods i.e it has access to them (but not vice versa, hence the word 'inheritence'). For more information on inheritence see. perlboot and perltoot.{ package One; sub new { bless [], shift } sub onefunc { print "$_[0] in One::onefunc" } package Two; @ISA = 'One'; } my $two = Two->new; $two->onefunc(); __output__ Two=ARRAY(0x80fba1c) in One::onefunc
_________
broquaint
In reply to Re: Learning how to use inheritance...
by broquaint
in thread Learning how to use inheritance...
by kiat
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |