Class::Struct array assignment and access
- From: "nelson331" <nelson331@xxxxxxxxx>
- Date: 29 Apr 2006 11:31:21 -0700
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;
}
}
.
- Follow-Ups:
- Re: Class::Struct array assignment and access
- From: A. Sinan Unur
- Re: Class::Struct array assignment and access
- Prev by Date: Re: Perl script does not work
- Next by Date: FAQ 6.3 How can I pull out lines between two patterns that are themselves on different lines?
- Previous by thread: Perl script does not work
- Next by thread: Re: Class::Struct array assignment and access
- Index(es):
Relevant Pages
|