#!/usr/bin/perl BEGIN { use strict; use warnings; } package Utils; sub new { # discard my class... shift(@_); # ...and invoke LowUtils::new as though # it were called by our caller. LowUtils::new ( 'LowUtils', @_ ); } sub get_numlines { my $self = shift; return scalar @{$self->{FILEDATA}}; } sub DESTROY { print "\tthis is the Utils destructor\n"; } 1; # end package Utils package LowUtils; @LowUtils::ISA = qw ( Utils ) ; sub new { my $proto= shift(@_); my %args= @_; my $class = ref($proto) || $proto; my $self = {}; $self->{FILENAME} = $args{file}; $self->{FILEDATA} = []; bless $self, $class; $self->init; return $self; } sub init { my $self= shift(@_); my %args= @_; open DAT, $self->{FILENAME} or return undef; @{$self->{FILEDATA}} = ; close DAT; return $self; } sub DESTROY { print "\tthis is the LowUtils destructor\n"; } 1; # end package LowUtils my $utils = Utils->new ( file => $0 ); print 'Utils: lines = ', $utils->get_numlines, "\n"; undef $utils; my $low = LowUtils->new ( file => $0 ); print 'LowUtils: lines = ', $low->get_numlines, "\n"; undef $low; exit;