On 6/6/06, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
  $self->_read_file($self->{file})


$self is an blessed reference to an object (used from inside that object)

$self->_read_file() is the subroutine to call defined inside that object

$self->{'file'}; is a reference to a hash defined inside the object.
It's confusing, but if you ignore the "$self" and think of it as a
standalone top-down script, it makes more sense.

The syntax {} is for a hashref, it's just an un-named hashref inside
that object.

my $foo = new Foo;
print $foo->getFooKey();
$foo->setFooKey('new value');
print $foo->getFooKey();

package Foo;

sub new
{
 my $class = shift; #new Foo where "Foo" is the class name
 $self = bless {}, $class;
 $self->{'fookey'} = 'some value here'; #hashref accessible only
within Package Foo;
 return $self;
}

sub getFooKey
{
  my $self = shift;
  return $self->{'fookey'};
}

sub setFooKey
{
   my $self = shift;

   if (@_== 1) { #if there's another param, set that as the value
      $self->{'fookey'} = shift;
   }

  return $self;
}

1;

--
Anthony Ettinger
Signature: http://chovy.dyndns.org/hcard.html

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to