#!/usr/bin/perl -w
use strict;
use Player;
use Hand;
#...
my @pl;
push @pl, Player->new(name => Alice, strategy => aggressive);
push @pl, Player->new(name => Bob, strategy => conservative);
my $hand = Hand->new( players, \@pl );
$hand->play();
####
sub new {
my ($class, %arg) = @_;
# ...
bless {
# ...
_players => $arg{players} ,
}, $class;
}
sub play {
my ($self) = @_;
my %player;
$self->{_players}[0]->out(); # this works
# out() is a member function that prints some info about the Player
# add key containg ref to 1st player to %player and
# with value of a reference to a new anonymous hash
$player{$self->{_players}[0]} = {};
foreach my $this_player (keys %player) {
$this_player->out(); # this doesn't
}
}
####
Can't locate object method "out" via package "Player=HASH(0x1012ac74)" (perhaps you forgot to load "Player=HASH(0x1012ac74)"?) at Hand.pm line 63.