Re: Perl threads in Object Oriented code
- From: Martijn Lievaart <m@xxxxxxxxxxxxxxxx>
- Date: Mon, 30 Apr 2007 22:01:44 +0200
On Mon, 30 Apr 2007 11:19:35 -0700, Eric wrote:
Note the following line of code in the former (non OO) script:
my $thr = threads->new(\&get);
This line is calling the 'get' sub. So, if I were to use the OO scripts
shown, how should I implement this?
I tried doing the obvious, which was to change the line to:
my $thr = threads->new($clock->get());
But I got the following error:
thread failed to start: Undefined subroutine &main::1177952602 called at
./CC.pl line 19.
Other failed attempts were:
my $thr = threads->new(\&clock->get()); my $thr =
threads->new(Clock::clock->get()); my $thr =
threads->new($Clock::get());
Truthfully, I am not well versed at Object Oriented Perl (or anything
else). So at this point I was making guesses that weren't so educated.
Does anyone have a solution?
Try (untested):
threads->new(sub { clock->get(); });
or
threads->new(Clock::get, clock);
Your problem is that the method wants a first parameter, the self
parameter or iow the object it is invoked on. You *have* to pass that
parameter, above are two ways of doing that.
HTH,
M4
.
- References:
- Perl threads in Object Oriented code
- From: Eric
- Perl threads in Object Oriented code
- Prev by Date: Perl threads in Object Oriented code
- Next by Date: Re: hello world with perl
- Previous by thread: Perl threads in Object Oriented code
- Next by thread: Re: Perl threads in Object Oriented code
- Index(es):
Relevant Pages
|
|