... use threads; ... BEGIN { $Config{useithreads} or die "Recompile Perl with threads!"; } # end BEGIN ... switch($action) { case /adminpass(,|$)/ { print "Do adminpass ($hostname)\n" if($verbose || $debug); $t[++$#t]=threads->new(\&adminpass); next; } # end case /adminpass/ case /backup(,|$)/ { print "Do backup ($hostname)\n" if($verbose || $debug); $t[++$#t]=threads->new(\&backup); next; } # end case /backup/ case /buildhosts(,|$)/ { print "Do buildhosts ($hostname)\n" if($verbose || $debug); $t[++$#t]=threads->new(\&buildhosts); next; } # end case /buildhosts/ case /buildhostsdell(,|$)/ { print "Do buildhostsdell ($hostname)\n" if($verbose || $debug); $t[++$#t]=threads->new(\&buildhostsdell); next; } # end case /buildhostsdell/ etc... #### # Loop through all the threads my $thr; foreach $thr (threads->list) { # Don't join the main thread or ourselves if ($thr->tid && !threads::equal($thr, threads->self)) { $x=$thr->join; print 'TID ' . $thr->tid() . " returned: $x\n" if($verbose || $debug); } # end if } # end foreach # Exit the script cleanly exit 0;