Why doesn't $foo show up in the object? Ways around it are obvious -
just have a helper method: sub foo {return [qw/one two three/]} but I
don't understand why I don't have access to the variable within the
same package?

use strict;
use warnings;

use Data::Dumper;

my $t = T->new();

print Dumper($t->get);

package T;

my $foo = [qw/one two three/];

sub new
{
  my ($proto) = @_;
  my $class = ref($proto) || $proto;

  return bless {'foo' => $foo}, $class;
}

sub get
{
  my ($self) = @_;

  return $self->{foo};
}


1;

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to