I’m creating an array of Thread::Queue elements.
I’m doing that like this:
for (my $i=0; $i < $queues_amount; $i++){
$queues[i]=Thread::Queue->new;
}
However, while I’m filling it each queue with elements like this
$queues[$index]->enqueue($element);
I get the following error :
Can’t call method “enqueue” on an undefined value…
Could you help me with finding out what the problem is?
My perl version is 5.12.2.
You are not using the
$sigil on the$ivariable within your loop:If you had
use stricton, thesubsportion would have thrown an error about the barewordi. To catch many errors, placeuse warnings; use strict;at the top of all of your programs.It is also a bit more idiomatic to write it as: