我收到的時候我試圖運行我的第一個Perl腳本以下錯誤:[Perl的]:不是代碼引用......我的第一個劇本
[id=0 @ 0] : IP address "3.3.3.3" corresponds to device "core".
Thread 1 terminated abnormally: Not a CODE reference at ./dev_ithread.pl line 23.
[id=0 @ 1] : IP address "5.5.5.5" corresponds to device "border".
Thread 2 terminated abnormally: Not a CODE reference at ./dev_ithread.pl line 23.
這裏是我到目前爲止寫
#!/usr/bin/perl
use strict ;
use warnings ;
use diagnostics ;
use threads ;
use Config ;
$Config{useithreads} || die("\n---> Please recompile Perl with \<ithreads\> included. \n") ;
# IP parameterization of network elements.
my %device_ip = (
"core" => "3.3.3.3",
"border" => "5.5.5.5",
) ;
# Initialize devices' pool of threads.
my $index = 0 ;
my @device_thread =() ;
while(my ($key, $value) = each %device_ip)
{
push(@device_thread, threads->new(\&thread_job($key, $device_ip{$key}, $index))->join) ; $index = $index+1 ;
}
# Worker thread subroutine.
sub thread_job
{
my ($device, $ip, $index) = @_ ;
my $ithread = threads->tid() ;
print "[id=$ithread @ $index] : IP address \"$ip\" corresponds to device \"$device\". \n" ;
}
我會很感激,如果有人能幫我解決這個問題。 謝謝。
謝謝大家。有效! – user690182 2011-04-05 07:59:36
@ user690182:太好了。您現在可以接受您認爲最能幫助您解決問題的答案之一。 – musiKk 2011-04-05 08:11:14