Powered by Ajaxy
Digg StumbleUpon LinkedIn YouTube Flickr Facebook Twitter RSS Reset

Perl: How to use class

Perl: How to use class
{filelink=14327}

#!/usr/local/bin/perl -w
package Person ;
sub new{
    my $class = shift;
    my $person = {
        "Name"  => undef,
        "Occupation" => undef,
        "Email"  => undef,
    };
    bless($person, $class);    
    sub set_Person{
        my $self = shift;
        my ($name, $occupation, $email)= @_;
        $self->{'Name'} = $name;
        $self->{'Occupation'}= $occupation;
        $self->{'Email'}= $email;
    }
    sub get_Person{
    my $self = shift;
    while(($key,$value)=each(%self))
    {
        print "$key: $valuen";
    }
}
# Creating instances of classe 'Person'
$student = Person->new();
# Class initialization
$student->set_Person("Bill", "Gate", "bill@test.com");
# access class objects
$student->get_Person;
 $student->set_Person("Dem","test","demo@gmail.com");
 $student->get_Person;

Users who found this page were searching for:

  • python get username

No comments yet.

Leave a Comment