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


In reply to Re: Class::Struct example fails..syntax problem? by bbfu
in thread Class::Struct example fails..syntax problem? by JamesNC

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.