Click to See Complete Forum and Search --> : Thread::Queue wanting to add an array or hash


scragar
04-05-2009, 08:14 AM
Long story short I want to insert a hash or array(doesn't matter which at this stage) into a Thread::Queue so that I can pull the whole array/hash out at a later time, I have tried a few things.
my $temp = {
'url'=>$1,
'data'=>$2
};
$mq->enqueue($temp);## Invalid value for shared scalar
##########################
my %temp = (
'url'=>$1,
'data'=>$2
);
$mq->enqueue(%temp);## Adds 4 elements: 'url', $1, 'data', $2
$mq->enqueue($temp);## Adds, but I can't work out how to get it back :(
##########################
my @temp = ($1, $2);
$mq->enqueue(@temp);## Adds each element independently
Anyone any clues? I need to keep the values I'm inserting together, keep locking $mq over and over again to keep the values together sounds like a really bad solution. Anyone got any better ideas or noticed something I'm missing?

Sixtease
04-05-2009, 12:11 PM
I have no experience with Thread::Queue but the docs hint me that it should work the first way. What exactly does it do when you pass it the hashref? Isn't the error caused by some other code of yours that deals with the enqueued value? Try to post a minimal but self-contained code sample that manifests the error.

If all else fails and we don't figure out the solution, then a workaround might be to use FreezeThaw (http://search.cpan.org/perldoc?FreezeThaw). You'd simply freeze (i.e. stringify) the data structure on insert and thaw it upon withdrawal.

And you could still try to use an arrayref:
my @temp = ($1, $2);
$mq->enqueue(\@temp);
although I doubt strongly that this will help if the hashref way didn't work.