use person;
my $foo = Person->new();
$foo->name("Stefan");
$foo->age(20);
$foo->exclaim();
####
$bar = Person->new();
$bar->name("Yoda");
$bar->age(900);
$bar->exclaim();
####
$foo->name("Stefan");
####
Person::name( $foo , "Stefan” );
####
my $ref1 = { “name” => “Stefan”,
“age” => 20 };
my $ref2 = { “name” => “Yoda”,
“age” => 900 };
####
$ref1 = bless $ref1 “Person”;
$ref2 = bless $ref2 “Person”;
####
package Person;
require 5.004;
#use strict;
my $Person;
# These Variables are Static variables.
# All Person objects share these variables.
$Person::version = "1.00.01";
$Person::build = "\$ID:2255518";
# this only lets you create one person. I don't think you
# whan to do that.
# $Person::list = {};
sub new
{
my $class = shift;
# $person is a blessed reference to an anonymous hash
my $Person = {};
my $Person = bless $Person, $class;
return $Person;
}
sub name
{
# Get the reference to the hash that represents this person
$Person = shift;
# Set the name member of the anonymous hash to the argument
# of this function.
$Person->{NAME} = shift;
return $Person->{NAME};
}
sub age
{
# Get the reference to the hash that represents this person
$Person = shift;
# set the age member of the anonymous hash to the argument
$Person->{AGE} = shift if @_;
return $Person->{AGE};
}
sub exclaim
{
# Get the reference to the hash that represents this person
$Person = shift;
printf "I'm %s and i'm %d years old!\n",
$Person->{NAME},$Person->{AGE};
return 1;
}
return 1;
####
#!/usr/bin/perl
# use Person qw/name age exclaim/;
use person;
my $foo = Person->new();
# $foo->Person::name("Stefan");
$foo->name("Stefan");
# $foo->Person::name(20);
$foo->age(20);
# $foo->Person::exclaim();
$foo->exclaim();
$bar = Person->new();
$ bar->name("Yoda");
$ bar->age(900);
$ bar->exclaim();
# See, it's still here
$foo->exclaim();
####
my $foo->new( “Stephan”, 20 );
$foo->exclaim();
my $bar->new( “Yoda”, 900 );
$bar->exclaim();