1 | #!/opt/bin/perl |
1 | #!/opt/bin/perl |
|
|
2 | |
2 | # This small example script shows how to do non-blocking |
3 | # This small example script shows how to do non-blocking |
3 | # reads from a file handle. |
4 | # reads from a file handle. |
4 | |
5 | |
5 | use AnyEvent::Handle; |
6 | use AnyEvent::Handle; |
6 | my $cv = AnyEvent->condvar; |
7 | my $cv = AnyEvent->condvar; |
… | |
… | |
9 | AnyEvent::Handle->new ( |
10 | AnyEvent::Handle->new ( |
10 | fh => \*STDIN, |
11 | fh => \*STDIN, |
11 | on_eof => sub { $cv->broadcast } |
12 | on_eof => sub { $cv->broadcast } |
12 | ); |
13 | ); |
13 | |
14 | |
14 | $ae_fh->push_read_line (sub { |
15 | $ae_fh->push_read (line => sub { |
15 | my ($ae_fh, $line) = @_; |
16 | my ($ae_fh, $line) = @_; |
16 | print "Got line [$line]\n"; |
17 | print "Got line [$line]\n"; |
17 | |
18 | |
18 | $ae_fh->push_read (sub { |
19 | $ae_fh->push_read (sub { |
19 | my ($ae_fh) = @_; |
20 | my ($ae_fh) = @_; |