Update: it would seem the problem is actually located within this part:

while(my $line = $buffer->sysreadline($fh)) { chomp($line); $self->_process($line); } }
and thus really has nothing to do with the actual select call...looks like I need to divert my attention to seeing what goes wrong in the sysreadline() call :/

Update 2 Well, what do you know, if sysreadline always appends a lineend to its return call, even when the actual line itself is empty, then it'll always evaluate to true, and the inner while loop above will never exit. Now if you'll all please excuse me, I need to find a really hard object to bang my head against for wasting your and my time in this way ;-)


Esteemed monks,

this has been baffling me for a few days already so I thought I might turn to you all for help. I have the following little while/select loop in my code:

sub run { while(1) { my @ready; print "about to check buffers\n"; unless(@ready = $buffer->ready) { select(undef, undef, undef, 0.001); next; } print "just after checking buffers\n"; foreach my $fh (@ready) { my $self = $objects{$fh}; while(my $line = $buffer->sysreadline($fh)) { chomp($line); $self->_process($line); } } } }
Note that $buffer in this case points towards a little thingamabob I wrote on top of IO::Select. Suffice to say that $buffer->ready performs an IO::Select->can_read with a timeout of 0.001. What's going wrong here is that the 2 print statements are executed once when the script is started and then never again. I know the while loop is being walked through time and time again, because everytime there is something available in @ready it is indeed processed in the second part of the loop. I've tried changing the 2 print statements to print explicitly to STDOUT but no such luck either. I even tried to blame my poor lil' WinXP box but then it turned out the FreeBSD server does the same. Any ideas on what this might be?


Remember rule one...

In reply to select loop madness by Forsaken

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.