Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: How to create a two dimensional queue in Perl

by rjt (Curate)
on Aug 04, 2013 at 09:53 UTC ( [id://1047782]=note: print w/replies, xml ) Need Help??


in reply to How to create a two dimensional queue in Perl

Based on your previous questions1, you are probably talking about threads. As Corion pointed out, Thread::Queue provides queue functionality to threads. According to its documentation (reformatted for brevity):

Any data types supported by threads::shared can be passed via queues: a) Ordinary scalars, b) Array refs, c) Hash refs, d) Scalar refs, e) Objects based on the above. Ordinary scalars are added to queues as they are.

If not already thread-shared, the other complex data types will be cloned (recursively, if needed, …

Your question here is very vague (please read How do I post a question effectively?), but taking your meaning of "two dimensional queues" as literally as I can, I believe a simple anonymous array ref (constructed with  [ ... ]) would work for you. Something like this:

use Thread::Queue; my $q = Thread::Queue->new; # Later, in producer thread(s) ($first and $second # represent the 2 dimensional tuple you wish to enqueue) $q->enqueue( [ $first, $second ] ); # Anonymous array ref # Later still, to signal the end of all elements: $q->enqueue(undef); # In the consumer thread(s): while (defined (my $ref = $q->dequeue)) { my ($first, $second) = @$ref; # Dereference array # ... Process $first and $second }

That's pretty much the pattern. You should be able to easily adapt it to your needs. If not, write up a better description of what you need, and we'll help you from there.

____________
1. meena's recent threads: Create your own signal in Perl, Alarm In Perl

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1047782]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (5)
As of 2024-03-29 08:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found