http://www.perlmonks.org?node_id=592884


in reply to Re^2: Stuck on packages
in thread Stuck on packages

A simple getter method might look like:
sub get_foo { my $self = shift; return $self->{foo}; }
Example:
use strict; use warnings; package Foo; sub new { my $class = shift; return bless { foo => "bar!\n" }, $class; } sub get_foo { my $self = shift; return $self->{foo}; } 1; my $foo = Foo->new; print $foo->get_foo;
The above code will print bar! There are many modules on CPAN that can create getter and setter methods for you, Class::Accessor and Class::MethodMaker are a couple of examples