package PointX; use strict; use warnings; use Scalar::Util qw(refaddr); use Carp qw(carp cluck croak confess); our $VERSION = '0.1b'; { my %xcord; my %ycord; sub new { my ($class, $cords) = @_; my $new_object = bless \do{my $anon_scalar;}, $class; $xcord{refaddr $new_object} = $cords->{'x'}; $ycord{refaddr $new_object} = $cords->{'y'}; return $new_object; } sub DESTROY { my ($self) = @_; delete $cord{refaddr $self}; return; } sub set_x { my($self, $xcord) = @_; $xcord{refaddr $self} = $xcord; return ($xcord{refaddr $self}); } sub get_x { my($self) = @_; return ($xcord{refaddr $self}); } sub set_y { my($self, $ycord) = @_; $ycord{refaddr $self} = $ycord; return ($ycord{refaddr $self}); } sub get_y { my($self) = @_; return ($ycord{refaddr $self}); } } # end of internal scoping. 1; #### package PointX; use strict; use warnings; use Scalar::Util qw(refaddr); use Carp qw(carp cluck croak confess); our $VERSION = '0.1b'; { my %cord; sub new { my ($class, $cords) = @_; my $new_object = bless \do{my $anon_scalar;}, $class; $cord{refaddr $new_object}->{'x'} = $cords->{'x'}; $cord{refaddr $new_object}->{'y'} = $cords->{'y'}; return $new_object; } sub DESTROY { my ($self) = @_; delete $cord{refaddr $self}; return; } sub set_x { my($self, $xcord) = @_; $cord{refaddr $self}->{'x'} = $xcord; return ($cord{refaddr $self}->{'x'}); } sub get_x { my($self) = @_; return ($cord{refaddr $self}->{'x'}); } sub set_y { my($self, $ycord) = @_; $cord{refaddr $self}->{'y'} = $ycord; return ($cord{refaddr $self}->{'y'}); } sub get_y { my($self) = @_; return ($cord{refaddr $self}->{'y'}); } } # end of internal scoping. 1; #### #!/usr/bin/perl use strict; use warnings; use PointX; my $point = PointX->new({x=>3, y=>20}); print "The x cord is ".$point->get_x()."\n"; print "The y cord is ".$point->get_y()."\n"; $point->set_x(10); print "The x cord is ".$point->get_x()."\n"; print "The y cord is ".$point->get_y()."\n"; #### The x cord is 3 The y cord is 20 The x cord is 10 The y cord is 20