Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Re: What is the correct way to use Thread::Queue::Any ?

by fx (Pilgrim)
on Jan 07, 2004 at 17:45 UTC ( [id://319539] : note . print w/replies, xml ) Need Help??


in reply to Re: What is the correct way to use Thread::Queue::Any ?
in thread What is the correct way to use Thread::Queue::Any ?

I thought that enqueuing an undef would have stopped that while loop and hence didn't much care about how it would interact with printf.

Is the behaviour of enqueuing (or perhaps more specifically dequeuing) undef's under Thread::Queue::Any different than under Thread::Queue for some reason that I'm not thinking of?

Many thanks.

  • Comment on Re: Re: What is the correct way to use Thread::Queue::Any ?

Replies are listed 'Best First'.
Re: Re: Re: What is the correct way to use Thread::Queue::Any ?
by liz (Monsignor) on Jan 07, 2004 at 17:56 UTC
    while( my($returned_value) = $queue->dequeue ) {

    You forget that $queue->dequeue always returns an array with at least 1 element. So the condition being checked is always 1 or higher. Something like:

    while( my ($returned_value) = $queue->dequeue ) { last unless defined $returned_value;
    should do the trick, I think.

    Liz

Re: Re: Re: What is the correct way to use Thread::Queue::Any ?
by ysth (Canon) on Jan 07, 2004 at 20:03 UTC
    I thought that enqueuing an undef would have stopped that while loop
    Nope, that's a list assignment in scalar context, which evaluates to the number of items on the right of the assignment.