-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

>>>>> "Rob" == Rob Dixon <[EMAIL PROTECTED]> writes:

    Rob> Sukrit wrote:
    >> Hi Listers, How do i delete the last 12 (or so) lines of a
    >> large file (400+ lines) without loading the whole into memory.

    Rob> 400 lines isn't too huge. I would say just read the file once
    Rob> to count the lines. Then re-read it, printing twenty less
    Rob> lines than you counted.  It's dirty but it's quick :)

    Rob> I'll even have a stab at the code for you:

    Rob>     use strict; use warnings;

    Rob>     open FILE, 'ppm_search.txt' or die $!; my $lines = grep
    Rob> 1, <FILE>; seek FILE, 0, 0 or die $!; $lines -= 20; print
    Rob> <FILE>.'' while ($lines--);


While waiting for your reply, my goals changed a bit. i got some sort
of worm (redlof if you must know) on my windows machine (with some
11000 files affected). It tags to the end of every html file, so i
didn't want chomping of last 12 lines of files that hadn't got it :)
But i must say this brevity is the soul of wit and you guys sure are
witty (it'll take me a while to understand your codes!).

What i like about perl is that there are levels to it, my code works
it's no where as elgant as yours but it works. Elegance can wait but i
hope it'll come to me one day :)

sub clean_file1 {
my $file_to_clean = $_[0];
my @clean_array;
open(TO_CLEAN, $file_to_clean) || die "Can't Open File Stopping: $!";
#populate clean_array, with file without script
foreach(<TO_CLEAN>){
  if($_ =~ /\bKJ_start()\b/) {
    last;} 
  else {
    push(@clean_array, $_);}
}
close(TO_CLEAN) ||die "can't close1";

#write clean_array back to file
open(CLEANED,">$file_to_clean") || die "Hey Can't Open Stopping: $!";
foreach(@clean_array){print CLEANED $_;}
close(CLEANED);
}


    Rob> Cheers,

    Rob> Rob

Regards
sukrit Or 
Just Another Perl Lamer ;)
PS Sorry for onlist mail i always manage to forget that reply-to
isn't set to the list
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: Processed by Mailcrypt 3.5.8 <http://mailcrypt.sourceforge.net/>

iD8DBQE+NC4aWQMs1XfYH8QRAi27AJ9xQjM1gu1IpC8075FeNFy0XBw2BQCeJ4NJ
BXOBx9bi/DZGal0jCWSr4lY=
=exW5
-----END PGP SIGNATURE-----

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to