f



creating thread in PERL

hi experts,

my code is as simple as the follow.

use Thread;
$thr = new Thread \&sub1; # Spawn the thread

$thr->detach; # Now we officially don't care any more

sub sub1 {
        $a = 0;
        while (1) {
            $a++;
            print "\$a is $a\n";
            sleep 1;
        }
}


however, when i compile it. The error occur stating "Undefined
subroutine &threads::new called at sample_thread.pl line 2.". What is
the reason?

0
6/5/2006 4:02:01 AM
comp.lang.perl.misc 33233 articles. 2 followers. brian (1246) is leader. Post Follow

2 Replies
454 Views

Similar Articles

[PageSpeed] 25

janicehwang1325@yahoo.com wrote:

> hi experts,
> 
> my code is as simple as the follow.
> 
> use Thread;
> $thr = new Thread \&sub1; # Spawn the thread


Try:

$thr = Thread->new(\&sub1);


> $thr->detach; # Now we officially don't care any more
> 
> sub sub1 {
>         $a = 0;
>         while (1) {
>             $a++;
>             print "\$a is $a\n";
>             sleep 1;
>         }
> }
> 
> 
> however, when i compile it. The error occur stating "Undefined
> subroutine &threads::new called at sample_thread.pl line 2.". What is
> the reason?


-- 
Brian Wakem
Email: http://homepage.ntlworld.com/b.wakem/myemail.png
0
Brian
6/5/2006 7:48:37 AM
erm.. i din really get your reply. However, i do solve the problem by
just reinstall Perl on FreeBSD.

Brian Wakem wrote:
> janicehwang1325@yahoo.com wrote:
>
> > hi experts,
> >
> > my code is as simple as the follow.
> >
> > use Thread;
> > $thr = new Thread \&sub1; # Spawn the thread
>
>
> Try:
>
> $thr = Thread->new(\&sub1);
>
>
> > $thr->detach; # Now we officially don't care any more
> >
> > sub sub1 {
> >         $a = 0;
> >         while (1) {
> >             $a++;
> >             print "\$a is $a\n";
> >             sleep 1;
> >         }
> > }
> >
> >
> > however, when i compile it. The error occur stating "Undefined
> > subroutine &threads::new called at sample_thread.pl line 2.". What is
> > the reason?
>
>
> --
> Brian Wakem
> Email: http://homepage.ntlworld.com/b.wakem/myemail.png

0
janicehwang1325
6/12/2006 3:47:43 AM
Reply: