Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Perl objects

by pr09 (Novice)
on Jun 14, 2011 at 06:02 UTC ( [id://909515]=perlquestion: print w/replies, xml ) Need Help??

pr09 has asked for the wisdom of the Perl Monks concerning the following question:

Hi All, I am new to perl and i have a project to be completed. I have an Class Employye and all the attributes of it. Now i have to create an object on this class and use it to access other methods like Display,update,get and set. I am new to this OOPS and don;t know how to implement it. Note:All the user details are to given by the user and are not hard coded. Can you please help me out!

Replies are listed 'Best First'.
Re: Perl objects
by Anonymous Monk on Jun 14, 2011 at 06:12 UTC
      The project i should have an employee class. The attributes of these class are name,dob etc.. Four methods are to be used like display,update,get and set. The main method should ask the number of employees. Next the user has to enter all the attributes and all this will be saved in a file. Now a method say display method has to called alongwith the argument which you want to retrive,say name. i created a class as shown below: package Employee; sub new { my $self = { _Name => undef; _DOB => undef; }; bless $self,'Employee'; return $self; } sub DisplayDetails { } package main; print "Enter the number of Employees"; $employee_count=<STDIN>; My doubt it how to access this display method using the object.

        My doubt it how to access this display method using the object.

        First you create an object calling class method new

        my $foo = Employee->new;
        Then you call the object method display, on the object $foo
        $foo->display;

        I suggest you review carefully the book/tutorial which taught you about package ... because calling methods is basic syntax.

        Its covered in various places, including the free book Modern Perl a description of how experienced and effective Perl 5 programmers work....You can learn this too.

        Also, FYI, you have a question, not a doubt, see "Question" vs "Doubt"

        The other Anonymous monk
Re: Perl objects
by 7stud (Deacon) on Jun 14, 2011 at 07:58 UTC
    You might also want to consider reading perltoot(which you can google).

      In fact, perltoot comes with Perl.

      perldoc perltoot

      will show that documentation.

      Also, http://perldoc.perl.org has that file available via perltoot, short-linkable from this site via [doc://perltoot].

Re: Perl objects
by sundialsvc4 (Abbot) on Jun 14, 2011 at 17:15 UTC

    Also consider Moose, unless this is out of scope for the project or assignment.   This will dramatically reduce the complexity of tasks such as this one.

      Moose and perltoot are new concepts,surely i will read about them. Thanks.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (4)
As of 2024-04-25 17:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found