Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi,
I have two script one in perl and one in expect.I am creating multiple thread through perl.In a single thread i am creating a new process where i exec my expect scripts.But after running the perl file , i get an error message

Can't locate object method "join" via package "threads=SCALAR(0x81e2d5 +0)0" (perh aps you forgot to load "threads=SCALAR(0x81e2d50)0"?) at ./thread1 lin +e 15. A thread exited while 2 other threads were still running. panic: MUTEX_DESTROY.

The two files are attached.Please help me. thanks in advanced

#!/usr/bin/perl -w use threads; ######### Main Starts here ######### for($i=0;$i<10;$i++) { $th.=$i; $th = threads->new(\&sub2,$i); } for($i=0;$i<10;$i++) { $th.=$i; $result = $th->join; $result = $th->eval; $th->detach; } ##### Subroutine 2 defined for thread creation ##### sub sub2 :locked { my @para = @_; my $t = $_[0]; my $temp="test"; my $user=$temp.$t; if (!defined($pid = fork)) { die "Cannot fork\n"; } elsif ($pid == 0 ) { exec("./sshex $user"); } else { waitpid($pid,0); } } #!/usr/bin/expect set ip "164.99.152.91" set user [ lindex $argv 0 ] set at "@" set pass "novell" set mac "$user$at" set path /home/$user/$user set sec [clock seconds] set realm "testRealm" set timeout 20 #spawn "/bin/sh" set file [ open $path w+ ] spawn ssh $user$at$ip sleep 1 puts $file "$sec" expect { "$user$at$ip's password:" { send "$pass\r" expect "$mac" { send "kinit $user$at$realm\r" expect "$user$at$realm's Password:" send "novell\r" sleep 1 expect "$mac" send "ldapsearch -Y GSSAPI -h 164.99.155.248 -b \" +\" -s base\r" sleep 5 expect "$mac" } } "Permission denied" { puts :Error in password" } } set sec1 [clock seconds] puts $file "$sec1"

Replies are listed 'Best First'.
Re: regarding perl thread
by johnnywang (Priest) on Aug 19, 2004 at 07:05 UTC
    The error is caused by the line:
    $th.=$i; # $th is "threads=SCALAR(0x81e2d50)", so you see "threads=SCA +LAR(0x81e2d50)0"
    I'm not sure what that line is doing here, it doesn't make sense to me.