Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Perl Misc (http://www.velocityreviews.com/forums/f67-perl-misc.html)
-   -   Regarding Inheritance (http://www.velocityreviews.com/forums/t889703-regarding-inheritance.html)

Mahesh 12-17-2004 04:36 AM

Regarding Inheritance
 
I have two packages package1 and package2.

Suppose this the code of package1
package package1;

my $file_scope_var = "var in package1"

sub new
{
my $proto = shift;
my $self = { };
my $class = ref ($proto) || $proto;
bless ($self, $class);
$self->{NAME} = undef;
}

sub print_package1
{
my $self = shift;
my $name = $self->NAME();
my $file_scope_var = $self->file_scope_var();
print"\n\n Name is $name and file scope var is $file_scope_var";
}


suppose the code of package2 is
package package2
@ISA=("package1");

sub new
{
my $proto = shift;
my $self = { };
my $class = ref ($proto) || $proto;
}

sub print_package2
{
my $self = shift;
$self->print_package1();
}

now my problem is that since Iam inheriting package1 into package2.
and Iam calling print_package1 in package2.

Will that call to print_package2 will print file_scope_var value or
not. Since it is a file scope variable will it get printed when we call
print_package2 or not.

Please help me in this soon as I was stuck in the middle of the work.
Thanks and Regards,
Mahesh


Sherm Pendley 12-17-2004 05:23 AM

Re: Regarding Inheritance
 
Mahesh wrote:

> Will that call to print_package2 will print file_scope_var value or
> not. Since it is a file scope variable will it get printed when we call
> print_package2 or not.


Have a look at "perldoc perltooc", in the section "Inheritance Concerns"
for a discussion of class variables and inheritance mix.

sherm--

--
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org

Sherm Pendley 12-17-2004 05:25 AM

Re: Regarding Inheritance
 
Mahesh wrote:

.... twice. Please don't do that. We heard you the first time.

sherm--

--
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org


All times are GMT. The time now is 01:51 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.