in reply to Class::Struct example fails..syntax problem?

From the Class::Struct docs (emphasis added):

    Class ('Class_Name' or '*Class_Name')
        The element's value must be a reference blessed to the named class
        or to one of its subclasses. The element is not initialized by
        default.

        The accessor's argument, if any, is assigned to the element. The
        accessor will "croak" if this is not an appropriate object
        reference.

So, basically, your ru_utime and ru_stime elements are not yet initialized. You must do so yourself, like so:

#!/usr/bin/perl use Data::Dumper; use Class::Struct; use strict; struct( rusage => { ru_utime => 'timeval', # seconds ru_stime => 'timeval', # microseconds }); struct( timeval => [ tv_secs => '$', tv_usecs => '$', ]); # create an object: my $t = new rusage; # Initialize ru_utime and ru_stime $t->ru_utime(new timeval); $t->ru_stime(new timeval); # $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); print Dumper($t),"\n";

Also, you must put quotes around 'timeval' so that it will pass strict.

bbfu
Black flowers blossom
Fearless on my breath

Replies are listed 'Best First'.
Re: Re: Class::Struct example fails..syntax problem?
by JamesNC (Chaplain) on Apr 18, 2003 at 21:57 UTC
    ah ha.. thank you very much bbfu :)