Assuming your question is not related to threads (since nothing of what you said in this ... thread relates to threads), my understanding is that you need a queue of items, in which each item is itself a list of successive actions to be performed together one after the other when a certain state is reached. This is not really a queue of queues, but rather a queue of lists.
If such is the case, then an AoA is probably what you need. Something like this:
my @queue = ( [$action1, $action2, $action3], [$action4, $action1, $ac
+tion3], ...);
# or possibly;
my @queue = ( [1, 2, 3], [4, 1, 3]);
# where [1, 2, 3] is a reference to an array of subscripts on an array
+ of actions defined somewhere else.
To add an item to the queue:
push @queue, [7, 3, 0, 9];
Which results in the following data structure:
0 ARRAY(0x80359f90)
0 1
1 2
2 3
1 ARRAY(0x8035a050)
0 4
1 1
2 3
2 ARRAY(0x803561e8)
0 7
1 3
2 0
3 9
To retrieve and remove a list of actions from the queue:
my $action_ref = shift @queue;
Now, $action_ref is [1, 2, 3], i.e. a reference to an anonymous array containing (1, 2, 3). You can now retrieve the actions one after the other from that anonymous array. For example, if you want to list the actions you've just dequeued:
print $_, " - " foreach @$action_ref; # prints: 1 - 2 - 3 -
Is this what you need?
|