> Öznur Taþtan wrote:
>
> > Hi,
> > 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?
>
> Specifically?  This:
>  [EMAIL PROTECTED];
> You have just assigned an integer [the count of elements in the parameter
list] to $r
>    print $r->ru_stime->tv_secs;
> Here you have tried to reference the ru_stime member of an integer.
>
> In general, I see a conceptual problem here.  What does "r" tell you about
the intended
> usage of the variable?  Or "t"?  [I will grant that the use of t as an
abbreviation for
> time is very common, but three extra characters do not cost that much for
the time saved
> in understanding and debugging the code.]  Perl can support very natural
styles of
> coding.  If you are going to use Perl, you should make use of that
feature,  Actually, C
> does also.  From the start, C compilers offered support for a minimum of
32 significant
> characters in identifiers.  C programmers just failed to make good use of
this.  Perl
> offers even more flexibility.
:)))))
That is just little program to test the question/  I have copied from module
description in cpan.org, so i also don't know what " ru_"" or "tv_".
But that doesn't mean I am cryptic if I weren' t I wouldn't be in trouble in
decoding a program that I have wrote last year:/

> Cryptic, everything-is-an-abbreviation coding style is a relic of a
not-so-long-ago time
> when hardware resources were expensive, and editing facilities primitive.
Please let it
> pass away along with the ill-fated 20th Century.
> [Escuse me if I'm going on a bit long here.  I'm in the process of
installing the module
> you are using, which has necessitated the force install of the package:
> ftp://archive.progeny.com/CPAN/authors/id/N/NW/NWCLARK/perl-5.8.3.tar.gz,
which sounds
> like a [possibly incompatible] upgrade to Perl itself.  It is taking
awhile....
> Hooboy, thar they come... and they's a whole s---load o' files, thar,
matey!
> ...
>   CPAN.pm: Going to build N/NW/NWCLARK/perl-5.8.3.tar.gz
>
> Program too big to fit in memory]
>
> That's OK.  the perldoc utility still runs, so we can see what kind of
animal we're
> working with.
>
> >
> > thanks
> > oznur
> >
> > use Class::Struct;
> >
> >     struct( rusage => {
> >         ru_utime => timeval,  # seconds
> >         ru_stime => timeval,  # microseconds
> >     });
>
> Is there a timeval class?  The values for these pairs ...yacketty-yack...
>
> >     struct( timeval => [
> >         tv_secs  => '$',
> >         tv_usecs => '$',
> >     ]);
>
> Oh, now I see.  Unfortunately, the compiler, reading in the same direction
as I,
> probably does not get here.  This should be defined above, or in a package
called with
> use.  Files are also cheap.  There is no extra price to maling a discrete
package file
> for each struct.  This will also allow for more flexible use of each
> struct/class/package you design.
>
> >     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);
>
> Don't do this.  The & operator is needed only in special cicumstances

I was wondering when to use this &?

> >
> >
> >     sub print_rusage{
> >     my $r=new rusage;
> >     [EMAIL PROTECTED];
> >    print $r->ru_stime->tv_secs;
> >   }
>
> I think I asnwered your immediate issue in the first paragraph of my
response.  I wish I
> could offer more assistance, but I have no idea what "ru_" or "tv_" or
"usecs" as
> opposed to "secs" would mean.  This puts me, other helpers, and you,
reviewing the code
> a month or a year later, at a great disadvantage.
>
> Can you try substituting some more descriptive identifiers, and repost?
Most editors
> have "Replace all" features that can make such substitutions very easy.
>
> Frankly, I don't see why you are doing this.  C structs are excellent
tools--for use
> within the C programming paradigm.  They are really something of a misfit
in Perl.  They
> have to be superimposed on structures that already are built, internally,
on C structs.
> The Perl hash or package will serve the functions of a C struct
wonderfully, with only a
> small paradigm shift.  I would really recommend that you get familiar with
Perl hashes
> and objects first, and exploit the native capabilities they offer, before
trying to
> import programming structures from outside the language.

May be i should sit and learn these. No pain no gain:)

> For compatibility with C, you might want to look into the XS interface.
This is the
> standard Perl interface for connecting with C code.  Generally, though,
unless you are
> doing highly cumputational work, native Perl functionality will serve
quite well.
>
> Joseph
Thanks  a lot!
oznur


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to