Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calling oo sub within an oo package?

Status
Not open for further replies.

wallythewhale

Technical User
Nov 5, 2002
14
US
Is it okay to do this?

package CC;
...
my $CC = new $CC;

sub new {...
sub add {
my ($self,$file) = @_;
...
sub proc {
my ($self,$file) = @_;
if (!$file) {
my $ret = CC->add($file); }
...
 
The subroutines can call on other OO methods within its own object with $self

my $ret = $self->add ($file);

If you called it as CC->add ($file), then in the add sub, $self = "CC" and $file is the file. $self->add, then $self is a reference to the active object and not just the name of the package.

my $CC = new $CC;

Not valid because $CC (the one being used) doesn't have a value.

$CC = new CC;

As far as I know, this should work just fine.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top