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

Re^2: POE/Tk/Fileevent Strangeness

by rcaputo (Chaplain)
on Jul 14, 2009 at 16:58 UTC ( #779984=note: print w/replies, xml ) Need Help??

in reply to Re: POE/Tk/Fileevent Strangeness
in thread POE/Tk/Fileevent Strangeness

You should find a different way to read from plain files, for at least two reasons.

Multiplexing plain files is generally pointless because the operating system always reports them as "ready to read". That is, your select_read() event will fire immediately and constantly. You may as well do:

_start=>sub { $TXT = $poe_main_window->Scrolled('Text')->pack; $_[KERNEL]->yield('_GetInput'); }, _GetInput=>sub { if (defined(my $line = <$ifd>)) { print STDERR $line; $TXT->insert('end', "-$.- $line"); $poe_main_window->update; $_[KERNEL]->yield('_GetInput'); } },

Your example works on UNIX because that OS treats everything as a file. Sockets, plain files, pipes, terminals, etc. have their quirks, but deep down UNIX treats them equally.

As you're discovering, Windows isn't as nice. Even Perl's select() is limited to only working with sockets. This is why you can't get input notification for your plain file handle. The yield() based example above should be portable everywhere.

A third, bonus issue: You've been mixing unbuffered, multiplexed I/O with buffered reads. This is a classical problem that tends to end badly. For example, the file handle may report not-ready-to-read because the data you're looking for is in the input buffer. The yield() based example will avoid it.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (5)
As of 2022-10-05 16:30 GMT
Find Nodes?
    Voting Booth?
    My preferred way to holiday/vacation is:

    Results (24 votes). Check out past polls.