Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

AnyEvent trying to read from a file

by wheelej (Initiate)
on Mar 04, 2017 at 20:13 UTC ( [id://1183662]=perlquestion: print w/replies, xml ) Need Help??

wheelej has asked for the wisdom of the Perl Monks concerning the following question:

I am trying to get AnyEvent to work on what I thought would be a simple bit code. My code does not work.

Clearly I have misunderstood something. I am trying run the following on a Windows PC. There are two processes, one a very simple routine which opens and appends data to a file and the second to read the data as and when it is written.
use strict; use warnings; use AnyEvent; use AnyEvent::Strict; open(my $fh, '<', 'C:/Temp/TestFile.txt') or die $!; my $done = AnyEvent->condvar; my $watcher = AnyEvent->io ( fh => $fh , poll => 'r' , cb => sub { my $input = <$fh>; print "Input [$input]\n"; if ( $input =~ /^End of processing file/ ) {$done->sen +d; } } ); $done->recv; close $fh or die $!; print "All done!\n";
However the code just terminates with the following:-
AnyEvent->io called with fh argument pointing to a file at script\test +\AnyEvent0.pl line 18.
Please can one point out what I have done wrong? Thanks.

Replies are listed 'Best First'.
Re: AnyEvent trying to read from a file
by huck (Prior) on Mar 04, 2017 at 20:26 UTC
      Thank you for your reply. It makes sense, so back to the drawing board for me.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1183662]
Front-paged by Arunbear
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (7)
As of 2024-04-23 07:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found