dbs has asked for the wisdom of the Perl Monks concerning the following question:
my $CF = new FileHandle "$cntrF", O_RDWR | O_APPEND || die '"cntrF' di +d not open $!\n";
My logic is if a file exists and has data in it, set flag to 1, set counter to 0, open filehandle as above, while (<$FH>), while (m/\b$flag\b/g), counter++, end while, if counter > 3.... I cannot do both, read to get the # of times flag appears in my file and append the flag + \n to my file.
thnkU!$| = 1; if ( -e $log ) { my $flag = 1; my $cntr = 0; no warnings; my $CF = new FileHandle "$cntrF", O_RDWR | O_APPEND || die "'cntrF +' did not open $!\n"; print $CF "$flag\n"; while (<$CF>) { while (m/\b$flag\b/g) { $cntr++; } } print "$cntr\n"; if ( $cntr <= 3 ) { _mailme($alertaddr, $Esubject, $log); $CF->close; exit 1; } elsif ( $cntr > 3 && $percnt >= 98 ) { _mailme($alertaddr, $Esubject, $log); $CF->close; exit 1; } else { $CF->close; print "closed\n"; exit 0;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: O_RDWR and O_APPEND???
by jwkrahn (Abbot) on Aug 30, 2011 at 20:21 UTC | |
|
Re: O_RDWR and O_APPEND???
by Eliya (Vicar) on Aug 30, 2011 at 22:53 UTC | |
|
Re: O_RDWR and O_APPEND???
by JavaFan (Canon) on Aug 30, 2011 at 20:56 UTC |