> Hi ,
> I have a problem in deleting all the lines in a file and saving it .
> Actually my log file keep appending all the messages for that
> i need to clean it up i.e delete all lines in it save it .
> when i do this initially file shows zero bytes , but as soon
> as the next message appends ,, file sizes jumps to the actual
> size and not from zero . I tried this with
> flock() option also . for Somereasons it is not working I
> could see some junk characters like this in the file
>
>
> [EMAIL PROTECTED]@[EMAIL PROTECTED]@[EMAIL PROTECTED]@[EMAIL PROTECTED]@[EMAIL
> PROTECTED]@^ Because of these characters, file size
> will not go to zero bytes.
>
> here is my script... Can somebody help on this ..
>
> for my $logfile (@filelist) {
> $lines = 0;
> open(FILE, "> $logfile") or die "Couldn't open
> $logfile : $!\n"; # This logfile keeps appending in a linux m/c
> flock(FILE,2);
> while (sysread FILE, $buffer, 4096) {
> $lines += ($buffer =~ tr/\n//);
> }
> print FILE Sudhakar;
> flock(FILE,8);
> close(FILE);
> print "No. of lines in $logfile", $lines, "\n";
> # system "vi $logfile +delete$lines +wq"; # Delete
> all the lines in the file ... This command will never work
> for me. Dont know }
>
Not quit sure what you are asking. AND you may have a race condition going
on as well. As far as zeroing the file, have you tried truncate? Something
like this maybe?
open (FILE, "+>", $file) or die "cannot open $file: $!";
flock (FILE, 2) or die "cannot flock $file: $!";
.... Do stuff
seek FILE, 0, 0;
truncate FILE, 0;
..... Do stuff
----
Also read up on some docs
perldoc -f open
perldoc -f flock
perldoc -f sysopen
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.745 / Virus Database: 497 - Release Date: 8/27/2004
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>