Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Trouble getting started with Perl OO

by zejames (Hermit)
on Oct 07, 2004 at 11:56 UTC ( [id://397269]=note: print w/replies, xml ) Need Help??


in reply to Trouble getting started with Perl OO

You are passing an argument to the new method, but not using it... Try

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;
Then use it like this :
use shapes; my $box; $box->{line1} = ' ---'; $box->{line2} = '| |'; $box->{line3} = ' ---'; my $box = shapes->new(shape => $box); $box->print_shape;

--
zejames

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://397269]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (4)
As of 2024-04-19 17:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found