i was wishing to make ... many of those structs with an index for each.
Here is one way, using anonymous hash references (see perlreftut):
#! perl use strict; use warnings; my $dimension = 3; # change as needed my @array; push @array, { data => $_, pointers => [] } for (1 .. $dimension); push @{ $array[0]->{pointers} }, ('hello world', 'the end is nigh', 't +his is the end'); push @{ $array[1]->{pointers} }, ('so long', 'and thanks', 'for all th +e fish', 42); push @{ $array[2]->{pointers} }, (3.141592653589793, 'ciao!'); for my $struct (@array) { print "\nData is ", $struct->{data}, ".\n"; print 'There are ', scalar @{ $struct->{pointers} }, " pointers al +located:\n"; print "\t$_\n" for @{ $struct->{pointers} }; }
See also: perldsc and perlref.
If your structs become too complex, it may be better to implement them as objects — see perlootut.
HTH,
Athanasius <°(((>< contra mundum
In reply to Re^5: How do I create a C-like struct with dynamic fields in Perl?
by Athanasius
in thread How do I create a C-like struct with dynamic fields in Perl?
by man-et-arms
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |