in reply to Deleting on Files

Phil's point about logrotate is well-made, but:

Why open it when you can clobber it?

If you're on a unix machine you could do:  echo '' > filename

In Perl the equivalent would be to open the file in a way that clobbers the contents.

Hope that helps,

andye

Replies are listed 'Best First'.
Re^2: Deleting on Files
by Anonymous Monk on Feb 28, 2007 at 16:17 UTC
    No, I am in a Windows box!
      Then you can still use Perl's open() in clobbering mode.
      Someone else has given an example.

      Best,

      andye

      Could I do something like this:

      #!/usr/bin/perl use strict; use warnings; open (FILE, '+<', 'sample.txt') or die "Could not open sample.txt: + $!"; close (FILE) or die "Could not close sample.txt: $!";

        Using > instead of < will open it for writing and truncate the file.

        open (FILE, '>', 'sample.txt') or die "Could not open sample.txt: $!"; close (FILE) or die "Could not close sample.txt: $!";


        ___________
        Eric Hodges