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;
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|