Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Trying to learn how to build a module

by davorg (Chancellor)
on Feb 02, 2001 at 19:54 UTC ( [id://56005]=note: print w/replies, xml ) Need Help??


in reply to Trying to learn how to build a module

Your get_name and set_name functions have now become object methods. This means that the first parameter they receive is the object reference. You need to deal with that before looking for the parameters you expect. A quick fix would be to do something like this:

sub get_name { my $self = shift; if (defined ($name)) { return $name; } else { return "error"; } } sub put_name { my $self = shift; $name = "$_[0]"; }

But you have a bunch of other problems. Your $name variable should become an entry in the object hash ($self->{name}) otherwise it will be shared between all instances of your object.

Good places to learn about this stuff are the perlboot and perltoot manual pages and Damian Conway's most excellent book Object Oriented Perl.

--
<http://www.dave.org.uk>

"Perl makes the fun jobs fun
and the boring jobs bearable" - me

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (5)
As of 2024-04-25 14:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found