kiat has asked for the wisdom of the Perl Monks concerning the following question:
Since there are two package names One and Two (corresponding to two classes), I'll need to save 'package One' as One.pm and 'package Two' as 'Two.pm'.#!/usr/local/bin/perl -w package One; sub new { $class = shift; print "creating object of class $class\n"; bless {}, $class; } package Two; @ISA = ("One"); sub new { $class = shift; print "creating object of class $class\n"; bless {}, $class; } $one = One->new(); $two = Two->new();
Another question I've is: What difference does '@ISA = ("One");' in Two.pm make? I mean there's still a need to declare 'use One' in main.pl before it will execute. When I comment out '@ISA = ("One");' in Two.pm, the code still runs.# main.pl use One; use Two; $one = One->new(); $two = Two->new(); # So, to execute the program, I type >perl main.pl
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Learning how to use inheritance...
by broquaint (Abbot) on Oct 07, 2003 at 15:46 UTC | |
Re: Learning how to use inheritance...
by Abigail-II (Bishop) on Oct 07, 2003 at 15:47 UTC | |
Re: Learning how to use inheritance...
by CombatSquirrel (Hermit) on Oct 07, 2003 at 15:48 UTC | |
Re: Learning how to use inheritance...
by fglock (Vicar) on Oct 07, 2003 at 18:07 UTC | |
Re: Learning how to use inheritance...
by kiat (Vicar) on Oct 08, 2003 at 09:31 UTC |