in reply to How to use a list of structs that contain a list of structs?

On your code,

The documentation says:

Giving a struct element a class type that is also a struct is how structs are nested. Here, timeval represents a time (seconds and microseconds), and rusage has two elements, each of which is of type timeval.

use Class::Struct; struct( rusage => { ru_utime => timeval, # seconds ru_stime => timeval, # microseconds }); struct( timeval => [ tv_secs => '$', tv_usecs => '$', ]);
start_update:
# create an object: my $t = new rusage; # $t->ru_utime and $t->ru_stime are objects of type timeval. # set $t->ru_utime to 100.0 sec and $t->ru_stime to 5.0 sec. $t->ru_utime->tv_secs(100); $t->ru_utime->tv_usecs(0); $t->ru_stime->tv_secs(5); $t->ru_stime->tv_usecs(0);
end_update:
Notice the notation:
struct(struct_name => {element => element_type});

You're missing the parentheses.

And as for emailing you our responses, an email address would be useful. The one you entered when you registered is kept private.

As for adamsj's comment, I think a /msg should've sufficed.

 

"cRaZy is co01, but sometimes cRaZy is cRaZy".
                                                      - crazyinsomniac

Replies are listed 'Best First'.
RE: Re: How to use a list of structs that contain a list of structs?
by Fastolfe (Vicar) on Sep 18, 2000 at 05:54 UTC
    Parenthesis don't matter here. struct is a function, and since Perl doesn't particularly care whether parenthesis exist in cases like this, his method will work just fine, and, IMO, is more readable. Think of => as a comma and pretend 'DiscourseSegment' is in quotes and things start to look normal from a syntax point of view.