Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

Re: How can I alert perl to a file write

by hiseldl (Priest)
on Dec 10, 2002 at 21:17 UTC ( #218916=note: print w/replies, xml ) Need Help??

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

The easiest way I can think of is to use the 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.

What time is it? It's Camel Time!

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://218916]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (3)
As of 2022-05-22 01:49 GMT
Find Nodes?
    Voting Booth?
    Do you prefer to work remotely?

    Results (78 votes). Check out past polls.