http://qs321.pair.com?node_id=218916


in reply to How can I alert perl to a file write

The easiest way I can think of is to use the Msg.pm module from Advanced Perl Programming (it's in the Networking directory).

In your running process you would put the listener code (ok, so it's more of a server), i.e.:

use Msg; use strict; my $host = 'localhost'; my $port = 8080; Msg->new_server($host, $port, \&login_proc); print "Server created. Waiting for events"; Msg->event_loop(); #--------------------------------------------------------------- sub login_proc { # Unconditionally accept an incoming connection request return \&rcvd_msg_from_client; } sub rcvd_msg_from_client { my ($conn, $msg, $err) = @_; if (defined $msg) { print "$msg\n"; } }

From the text, "The script calls new_server to create a listening socket (the program's network address) and then calls event_loop, an event dispatcher, which is a thin wrapper over select."

And the client code that would send a message to your running process (server):

use Msg; $conn = Msg->connect('localhost', 8080); die "Error: Could not connect\n" unless $conn; $conn->send_now("Message $i"); ($msg, $err) = $conn->rcv_now();

Use the server and client scripts from the book's example code because the code here is for illustrative purposes.

--
hiseldl
What time is it? It's Camel Time!