Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re^2: Perl objects

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


in reply to Re: Perl objects
in thread Perl objects

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.

Replies are listed 'Best First'.
Re^3: Perl objects
by Anonymous Monk on Jun 14, 2011 at 07:12 UTC

    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
      Thanks for the help. Will read the book.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://909523]
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: (7)
As of 2024-04-23 13:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found