Click here to get back home

Class::Struct - want to access structure within structure

 HomeNewsGroups | Search | About
 comp.lang.perl.modules    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
Class::Struct - want to access structure within structure nelson331 04-29-2006
Get Chitika Premium
Posted by nelson331 on April 29, 2006, 3:33 pm
Please log in for more thread options


I want to access a structure within a structure. Below is what I had
in mind. Please help.

#!/perl/bin/perl
use Class::Struct;

struct Step => {
number => '$',
otherstuff => '$',
};

struct Block => {
number => '$',
steps => '@', #should be an array of "Step"s
};

my $step1 = Step->new();
$step1->number(1);

my $step2 = Step->new();
$step2->number(2);

#will eventually be in side a loop @stepArray = (@stepArray,
$tempStep);
@stepArray = ($step1, $step2);

my $block1 = Block->new();
$block1->number(1);
$block1->steps(@stepArray); #this isn't working

@blockArray = (@blockArray, $block1);

#would then like to access the Steps within the Blocks
foreach $tempBlock (@blockArray) {
foreach $tempStep ($tempBlock->steps) { #
print $tempStep->number;
}
}


Posted by metaperl@gmail.com on May 1, 2006, 11:24 am
Please log in for more thread options



nelson331 wrote:

> my $block1 = Block->new();
> $block1->number(1);
> $block1->steps(@stepArray); #this isn't working

The docs for Class::Struct
http://search.cpan.org/~jhi/perl-5.8.0/lib/Class/Struct.pm

do not show that type of usage. Only this usage:
With one or two arguments, the first argument is an index specifying
one element of the array; the second argument, if present, is assigned
to the array element. If the element type is '@', the accessor returns
the array element value. If the element type is '*@', a reference to
the array element is returned.

-- meaning, that you can only put in one element at a time.


Also:
1 - what are you resorting to objects for in this case anyway? The
standard Perl data structures look like they can handle this problem.

2 - Class::Accessor is much more popular for this sort of thing. I
prefer Class::Prototyped myself.

3 - You might find some more help on perlmonks.org for this type of
question.

Good luck


Similar ThreadsPosted
data structure from XML::LibXML October 6, 2004, 6:22 pm
ANNOUNCE: GraphViz::Data::Structure 0.11 September 27, 2004, 11:31 pm
CPAN tarball structure for related web-server files? January 8, 2008, 4:39 pm
Perl Class::Struct October 13, 2005, 3:18 am
A doubt in using Class::Struct October 5, 2006, 2:33 pm
Class::DBI::Schema2Code V 1.01 July 29, 2004, 7:14 am
Class::Tree V 1.24 July 29, 2004, 7:15 am
[RFC] Class::DataStore May 13, 2005, 2:45 pm
RFC: new module Class::MakeIntrospecMethods October 18, 2004, 4:30 pm
[ANNOUNCE] New module Class::IntrospectionMethods December 6, 2004, 2:12 pm

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap