Öznur tastan wrote: > > I am trying to use struct as an argument of a function. > In the piece of code I try to use $t as a parameter of the print_usage function but > it gives the error: > > Can't call method "ru_stime" without a package or object reference at str.txt l > ne 28. > > Could anyone explain what is wrong?
Always: use strict; use warnings; > use Class::Struct; > > struct( rusage => { > ru_utime => timeval, # seconds > ru_stime => timeval, # microseconds > }); > > struct( timeval => [ > tv_secs => '$', > tv_usecs => '$', > ]); > > > my $t = new rusage; > > > $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_rusage($t); > > sub print_rusage{ > my $r=new rusage; > [EMAIL PROTECTED]; This line is your problem. In fact the previous line creates a new 'rusage' object which immediately gets thrown away and replaced by the '1' - the number of elements in @_. > print $r->ru_stime->tv_secs; > } > The subroutine should read: sub print_rusage{ my $r = shift; print $r->ru_stime->tv_secs; } HTH, Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>