我有一段 perl 脚本:
my $thread_count = 20
my %QUEUES;
my $current_queue=0;
while(defined($INPUT[$cnt]))
{
while (my @instance = $q1->fetchrow_array)
{
my $walk = "string";
push @{$QUEUES{$current_queue}},$walk;
$current_queue=($current_queue+1)%$thread_count;
}
while (my @instance = $q2->fetchrow_array) {
my $walk = "string";
push @{$QUEUES{$current_queue}},$walk;
$current_queue=($current_queue+1)%$thread_count;
}
}
我试图将命令推送到一个数组中,我决定将其保存在一个哈希中,因为我认为我可以让我的生活变得轻松而不是这样做if(!defined($QUEUES[$current_queue]))$QUEUES[$current_queue]=[];
我使用Data::Dumper
了一个常规的 for 循环,发现没有为 $QUEUE 中的任何键定义任何内容,从 0 到 $thread_count-1。这不是教科书自动复活的用法吗?我究竟做错了什么?