ADD ERROR CHECKING!
Lots of memory (small file)?
Read file line by line into a scalar, ignoring the line you want to omit. Close the
file, then open and overwrite with your scalar.
$ignore_line = 42;
$count = 0;
$file = '';
open(FH,"<file.txt);
while ($line = <FH>){
$count++;
$file .= $line unless ($count == $ignore_line);
}
close FH;
open(FH,">file.txt");
print FH $file;
close FH;
Limited memory (very large file)?
Read file line by line and write out to a temporary file, ignoring the line you want
to omit. Delete the original file and rename the temporary file.
open(INPUT,"<file.txt");
open(OUTPUT,">temp.txt");
$ignore_line = 42;
$count = 0;
while ($line = <INPUT>){
$count++;
print OUTPUT $line unless ($count == $ignore_line);
}
close OUTPUT;
close INPUT;
unlink('file.txt');
rename('temp.txt','file.txt');
--nigel
>>> Stéphane JEAN BAPTISTE <[EMAIL PROTECTED]> 06/22/01
>10:54am >>>
HI.
I'm looking for a method to delete the line number x into a file.
Is it simply possible ?
tks
This e-mail and any files transmitted with it are confidential
and solely for the use of the intended recipient.
ONdigital plc, 346 Queenstown Road, London SW8 4DG. Reg No: 3302715.