Class::Struct - want to access structure within structure

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

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

use Class::Struct;

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

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

my $step1 = Step->new();

my $step2 = Step->new();

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

my $block1 = Block->new();
$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;

Re: Class::Struct - want to access structure within structure

nelson331 wrote:

Quoted text here. Click to load it

The docs for Class::Struct

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.

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 for this type of

Good luck

Site Timeline