in reply to Trouble getting started with Perl OO
Then use it like this :package shapes; #constructor sub new { my ($invocant, %hash) = @_; my $class = ref($invocant) || $invocant; my $self = { shape => $hash{'shape'}, }; return bless $self, $class; } sub print_shape { my $self = shift; print $self->{'shape'}->{'line1'} . "\n"; print $self->{'shape'}->{'line2'} . "\n"; print $self->{'shape'}->{'line3'} . "\n"; } 1;
use shapes; my $box; $box->{line1} = ' ---'; $box->{line2} = '| |'; $box->{line3} = ' ---'; my $box = shapes->new(shape => $box); $box->print_shape;
|
|---|