Class::Struct array assignment and access

N

nelson331

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);

@blockArray = (@blockArray, $block1);

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

A. Sinan Unur

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

I don't understand what you need help with.
#!/perl/bin/perl

This is an odd shebang line for sure.
@blockArray = (@blockArray, $block1);

There is no mention of @blockArray before this line.

Make sure to put

use strict;
use warnings;

in your script, and tell us, please, what is your question?

Sinan

--
A. Sinan Unur <[email protected]>
(remove .invalid and reverse each component for email address)

comp.lang.perl.misc guidelines on the WWW:
http://augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
 
N

nelson331

The shebang line is for windows.
The @blockArray was only for example.

Basically, I want to access a structure within a structure. I need to
be able to store and retrieve.
 
A

A. Sinan Unur

@i39g2000cwa.googlegroups.com:

[ Please read the posting guidelines for this group, and quote some
context when you reply ]
The shebang line is for windows.

You don't need a shebang line for Windows.
The @blockArray was only for example.

Basically, I want to access a structure within a structure. I need to
be able to store and retrieve.

Please don't post pseudo-code. Post a short but complete script which
others can run (as described in the posting guidelines) to show what you
have tried and what does not work.

Sinan

--
A. Sinan Unur <[email protected]>
(remove .invalid and reverse each component for email address)

comp.lang.perl.misc guidelines on the WWW:
http://augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top