As you probly already know this produces an error about $Name being undeclared. So I tried this:package Obj; use strict; our $Name; sub new { my $proto = shift; my $class = ref $proto || $proto; my $self = bless {}, $class; return $self; } sub test { my $self = shift; print "$Name \n"; } package Test; use strict; our @ISA=("Obj"); $Name = 'Testing'; package main; my $t = new Test; $t->test;
Which results in printing nothing. So then I remember TheDamian's book, and the "SUPER::" package, so I figure if I _HAVE_ to I'll do this:#$Name = "Testing"; TO our $Name = "Testing";
I get the same results as before. Nothing is printed. So I delve into perltoot, perltooc, perlbot, and perlobj which present similar but not exactly the same thing style examples. Confused and wondering if I've been dreaming for the past few years of perl development, I hardcore the package for a sanity check:#$Name = "Testing"; TO $SUPER::Name = "Testing";
This code actually works and produces the desired output. Leaving me completely Confused. Is "SUPER::" only for subroutine location? I want to abstract out the "Obj" class from the "Test" Class. Ideally, I'd like the the test() method in the the Obj class be able to use the current package's $Name. What is the best way to acheive this?#$Name = "Testing"; TO $Obj::Name = "Testing";
In reply to Package Variables in Inheritance by reyjrar
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |