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


in reply to Apache log pipe doesn't write to log files

I haven't tested this, but this is how I would write it based on what you have provided.
#!/usr/bin/perl use strict; # split-logfiles # you don't need to test if it is open #$isopen = 0; my $myfile = "/var/tmp/test.log"; # no reason to do this testing # unless($isopen and -f $myfile) { # open the happy file here, but you may want to use >> if # you need to append rather then overwrite on each run open MYHAPPYFILE, ">$myfile" or die "Error opening $myfile"; # don't need to test if it is open because we # are dying if it isn't # $isopen = 1; # } while (my $log_file = <STDIN>) { printf MYHAPPYFILE "%s", $log_line; } exit 0;
And without commments:
#!/usr/bin/perl use strict; my $myfile = "/var/tmp/test.log"; open MYHAPPYFILE, ">$myfile" or die "Error opening $myfile"; while (my $log_file = <STDIN>) { printf MYHAPPYFILE "%s", $log_line; } exit 0;