in reply to Re^2: Stuck on packages
in thread Stuck on packages
Example:sub get_foo { my $self = shift; return $self->{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 examplesuse 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;
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^4: Stuck on packages
by Yoda_Oz (Sexton) on Jan 04, 2007 at 06:43 UTC | |
by SheridanCat (Pilgrim) on Jan 04, 2007 at 07:16 UTC | |
by Yoda_Oz (Sexton) on Jan 04, 2007 at 07:21 UTC | |
by shigetsu (Hermit) on Jan 04, 2007 at 10:09 UTC | |
by blazar (Canon) on Jan 04, 2007 at 21:07 UTC |