Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Active Munging via a pipe (code)

by Zaxo (Archbishop)
on Jan 17, 2002 at 06:51 UTC ( #139423=note: print w/replies, xml ) Need Help??


in reply to Active Munging via a pipe (code)

Here's yet another way, demonstrated from the shell:

Make the pipe, and...

$ mkfifo logpipe $ perl -e 'open PIPE, "< logpipe"; { select 1<<fileno(PIPE),undef,unde +f,undef; print <PIPE>;redo}' &
... start a simple server in the background. select makes it sleep till PIPE is readable. redo in a bare block loops forever. Kick the tires:
$ echo foo >logpipe foo $ echo far >logpipe $ far echo fie >logpipe fie $
The asynchronous operation of the server is shown in the staggered output. Clean up with
$ fg perl -e 'open PIPE, "< logpipe"; {select 1<<fileno PIPE,undef,undef,un +def;print <PIPE>;redo}' # do a Ctrl-C here $
I think this is the Right Way® to handle your log file problem. Sleeping till there is something to read will save a lot of load on the host.

Update: Changed to use mkfifo instead of mknod, and repaired a pasto in the timeout arg of select.

After Compline,
Zaxo

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (1)
As of 2023-06-04 21:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How often do you go to conferences?






    Results (22 votes). Check out past polls.

    Notices?