http://qs1969.pair.com?node_id=836562


in reply to Re^2: Simple inheritance question
in thread Simple inheritance question

Would have been nice if you could have named those "little things"

That's a fair point. Here's a modified version of the code doing what I think you might have been trying to do. I'm also realizing I may have misread the question, but I've got momentum now. Might as well paste what I have.

#!/usr/bin/perl # Use the warnings pragma rather than the -w flag use warnings; use strict; { package One; # Define a constructor for One sub new { my $class = shift; # Constructors need to know what class they +'re for my $self = {}; bless($self, $class); # Tell Perl what $self is being blessed +into } sub test { my $self = shift; # Is this an object method? Better grab $sel +f my $x = pop @_; # I usually shift from the argument list, but +whatever # Also, I like to be explicit about what I'm # popping/shifting from print "$x\n"; } } { package Two; use base "One"; # Two::new didn't add anything to One, so I removed it. sub eg { my $self = shift; # Is this an object method? Better grab $se +lf my $arg = pop @_; # pop() again? Okay, break it out and make +it explicit. $self->test($arg); # Is test() an object method? I'll use it a +s if it was. } } my $obj = new Two(); $obj->eg("hello");

Edit: Incidentally, I think jethro has the solution you're looking for. I've become so used to making everything explicit by spelling out object or module connections that I didn't even think of Exporter.