Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

Re: filtering my own output

by RhetTbull (Curate)
on Sep 06, 2001 at 19:50 UTC ( #110602=note: print w/replies, xml ) Need Help??

in reply to filtering my own output

I recommend Filter::Handle. I think it will do exactly what you want. I used it for the very same purpose -- to log the output a script without changing print statements, etc. Here's a sample script.
#!/usr/local/bin/perl use warnings; use strict; use Filter::Handle qw/subs/; #open the logfile open (LOGFILE,">>test.log") || die "open: $!"; #set up a sub to filter our output #print @_ to LOGFILE then also print it to STDERR Filter \*STDERR, sub { local $_ = "@_"; print LOGFILE scalar(localtime), ": $_"; $_ +}; #test it out by printing something to STDERR print STDERR "hello world\n"; #turn off filtering UnFilter \*STDERR; close LOGFILE || die "close: $!";
When run, this produces the following output:
/home/rhet/misc> ./ hello world /home/rhet/misc> cat test.log Thu Sep 6 11:46:24 2001: hello world /home/rhet/misc>

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://110602]
[Discipulus]: The Count of Moret; The Red Sphinx is a single book appeared with different titles. it is one of the best and alot of understimed Dumas book.
choroba has only read the first two
[Discipulus]: if i can suggest La Reine Margot too is a great book and obviously The Count of Monte Cristo that is a chef-d'œuvre
[Discipulus]: The red sphinx is about Rechilieu, absolutely thrilling
[erix]: thanks, Discipulus - I got them lined up at gutenberg :)
[erix]: I red the musketeers and Monte Cristo but both a very long time ago (many decades ago)
[erix]: *read

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (9)
As of 2017-05-24 07:21 GMT
Find Nodes?
    Voting Booth?