Subject: | the variation method returns an array (not a Node or Variation object) |
I think (from the doc), variations should work like this
my $var = $walker->variation(0);
print $var->move,"\n";
However, in the above snippet, $walker->variation(0) returns an array.
For example, with perl 5.8.8 for MSWin32 from ActivePerl, the following
code (which shows a workaround rather than the bug):
use Games::Go::SGF;
use Data::Dumper;
my $sgf = new Games::Go::SGF('(;GM[1]FF[4]SZ[19];B[pd](;W[cf]))');
my $move_no = 1;
while (my $walker = $sgf->move($move_no++)) {
if (ref($walker) eq 'Games::Go::SGF::Variation'){
my $var = $walker->variation(0);
print $var->move,"\n";
print ref($var),"\n"; # this is an ARRAY
my @deref = @{$var};
print ref($deref[0]),"\n";
print 'var move '."$move_no: ".$deref[0]->move,"\n";
print '$var is:';
print Dumper($var),"\n";
}
}
Prints out:
ARRAY
Games::Go::SGF::Node
var move 3: cf
$var is:$VAR1 = [
bless( {
'next' => undef,
'W' => 'cf',
'moves_to_first_variation' => 0
}, 'Games::Go::SGF::Node' ),
{
'next' => undef
}
];
A similar problem happens with the 'variations' method,which returns an
array of arrays rather than the expected array of Nodes.