in reply to Re: AnyEvent for I/O events
in thread AnyEvent for I/O events
use AnyEvent::Handle; my $cv = AnyEvent->condvar; my $ae_fh = AnyEvent::Handle->new ( fh => \*STDIN, on_eof => sub { $cv->broadcast } ); $ae_fh->push_read_line (sub { my ($ae_fh, $line) = @_; print "Got line [$line]\n"; $ae_fh->push_read (sub { my ($ae_fh) = @_; print "Got additional data:[\n".$ae_fh->rbuf."]\n"; if ($ae_fh->rbuf =~ s/^.*\bend\b//s) { print "'end' detected, stopping program\n"; $cv->broadcast; return 1; } return 0; }); }); $cv->wait;
(Note: See also the examples in the distribution of AnyEvent and it's POD docs.)
There are also utility functions for non-blocking socket creation planned for next releases of AnyEvent. And one day there will hopefully also a HTTP client module with AnyEvent support, perhaps someone would like to write it?
|
|---|