I've used threads before, but not with Perl.
I tried looking up these errors and using 'join' instead of 'detach' with no luck.
Here is the code I am currently using:
#!/usr/bin/perl -w
use warnings;
use threads;
use threads::shared;
$Linux='Linux';
$Greek='Greek';
my $thr1 = threads->create(\&work1);
sub work1 {
open(FILE,"/home/mine/text");
if (grep{/$Greek/} <FILE>){
print "/home/mine/text exists!\n"
}else{
system("echo '' > /dev/null");
}
close FILE;
$thr1->detach();
}
my $thr2 = threads->create(\&work2);
sub work2 {
$filename = "/home/mine/kcron";
if (-e $filename) {
print "/home/mine/kcron exists!\n";
}else{
system("echo '' > /dev/null");
}
$thr2->detach();
}
my $thr3 = threads->create(\&work3);
sub work3 {
open(FILE,"/home/mine/geek.txt");
if (grep{/$Linux/} <FILE>){
print "/home/mine/geek.txt exists!\n";
}else{
system("echo '' > /dev/null");
}
close FILE;
$thr3->detach();
}
select(undef,undef,undef,.1);
exit();
These are the current errors I am getting:
# ./unixthrd.pl
/home/mine/text exists!
Thread 1 terminated abnormally: Can't call method "detach" on an undefined value at ./unixthrd.pl line 21.
/home/mine/kcron exists!
Thread 2 terminated abnormally: Can't call method "detach" on an undefined value at ./unixthrd.pl line 33.
/home/mine/geek.txt exists!
Thread 3 terminated abnormally: Can't call method "detach" on an undefined value at ./unixthrd.pl line 45.
Perl exited with active threads:
0 running and unjoined
3 finished and unjoined
0 running and detached
Any advice much appreciated.