Although the documentation seems to discourage using AnyEvent::Handle
for anything but streaming things like sockets and pipes, using it for
files seems to work fine in the code below.
Any reason not to use it in this way?

use AnyEvent;
use AnyEvent::Handle;

open my $fh, "<", "foo.txt" or die;

my $handle = AnyEvent::Handle->new(
    fh       => $fh,
    on_error => sub { die "read error: $!"; },
    on_eof   => sub { print "done!\n"; },
    on_read  => sub {
        my( $hdl ) = @_;

        $hdl->push_read( line => sub {
            my( $h, $line ) = @_;
            print "line=$line\n";
        } );
    },
);

AnyEvent->condvar->recv;

_______________________________________________
anyevent mailing list
[email protected]
http://lists.schmorp.de/mailman/listinfo/anyevent

Reply via email to