Hi, Monks

Not really sure where to start with this issue, so I'll try and describe it as best I can and see whether anyone has heard of anything like this before. Please bear with me and let me know if I can provide any further details.

I'm building an OO based communication system utilising Microsoft MSMQ and multithreaded Perl v 5.16.2

The design uses one thread to receive message alerts from MSMQ and queue the message ID numbers for multiple separate worker threads to work on. I'm using threads to create the threads and Thread::Queue to control the queues internal to Perl. The worker thread creates an object representing the open MSMQ queue, then listens to the Thread::Queue for message ID numbers. When an ID comes in, it assigns the ID to the MSMQ object and requests the MSMQ message to be returned.

The problem occurs when I retrieve the message ID from the Thread::Queue, pass it directly to the MSMQ object and ask for the message - Nothing comes back. If I add a print statement to print out the message ID before requesting the message from the MSMQ object, everything works perfectly.

Works:

while($$queueObject{msmqLookupId} = $$self->{queue}->dequeue()) { print "$$queueObject{msmqLookupId}\n"; &{$$self->{handler}}($queueObject->peekMessage()); }

Doesn't work:

while($$queueObject{msmqLookupId} = $$self->{queue}->dequeue()) { &{$$self->{handler}}($queueObject->peekMessage()); }

Also doesn't work (though the print statement does print the correct value):

while($$queueObject{msmqLookupId} = $$self->{queue}->dequeue()) { &{$$self->{handler}}($queueObject->peekMessage()); print "$$queueObject{msmqLookupId}\n"; }

Does anyone have any idea what might be occurring here? The only thing I can think of is that Perl is doing something odd with the assignment of the scalar (such as assuming it isn't required and so not assigning it).


In reply to Odd scalar behaviour by SimonPratt

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.