#!/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 $self 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 $self 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 as if it was. } } my $obj = new Two(); $obj->eg("hello");