I didn't have the Programming Perl here, so did some checking. Used
Data::Dumper and the way it is being set, the children are empty.
In the Perl Cookbook under Useing Classes as Structs, I came across one
simliar to yours. It showed the way you were doing it and also like:
@{$node->children} = ("Craig", "Scott", "Cara");
and the output came back as:
[D:/CurrWrka/00CommonPerl] aapl224
$VAR1 = [
bless( {
'Object::id' => 'ID3148',
'Object::children' => [
'Craig',
'Scott',
'Cara'
],
'Object::name' => 'Murray'
}, 'Object' ),
bless( {
'Object::id' => 'ID0281',
'Object::children' => [
'NA'
],
'Object::name' => 'CRAIG'
}, 'Object' )
];
Murray
ID3148
CraigScottCara
CRAIG
ID0281
NA
Looks like from the COokbook either should work and it will take someone with a higher
understanding than me to explain.
Wags ;)
-----Original Message-----
From: Craig Moynes/Markham/IBM [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, August 22, 2001 13:55
To: [EMAIL PROTECTED]
Subject: Printing an array reference from within a struct
Hey Perl'ers,
I can't seem to print the array reference within the struct correctly
( I get a blank rather than the expected data).
I grabbed this idea Chapter 12, pg 336 of Programming Perl and it looks
like I followed their sample but something doesnt seme to be working
correctly.
Cheers,
#!/usr/bin/perl -w
use strict;
use Parse::RecDescent;
use Class::Struct;
select ( STDOUT );
$| = 1;
# my $wRX = "\[\\w\\-\]";
# my $commentRX = qr/^--/;
struct Object => {
name => '$',
id => '$',
children => '@',
};
my @MIB_TREE;
my $node = Object->new();
$node->name("Murray");
$node->id("ID3148");
$node->children(["Craig", "Scott", "Cara"]);
push @MIB_TREE, $node;
$node = Object->new();
$node->name("CRAIG");
$node->id("ID0281");
$node->children(["NA"]);
push @MIB_TREE, $node;
foreach my $object ( @MIB_TREE ){
print $object->name."\n";
print $object->id."\n";
print @{$object->children}; #< - Does not print children correctly
print "\n";
};
-----------------------------------------
Craig Moynes
IBM Global Services, Canada
[EMAIL PROTECTED]
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]