I think you are asking how to delete the first line and any blank lines correct?
Here goes:
Code:
open(FILE,"/path/to/file") | | die "can't open file";
@contents = (<FILE> );
close(FILE);
$count_lines=0;
foreach $line (@contents) {
$count_lines++;
chomp $line;
if ($count_lines == 1) {
$line = '';
}
if ($line ne '') {
$line = "$line\n";
push(@new_contents, $line);
}
}
open(FILE,">/path/to/file") | | die "can't open file";
print FILE @new_contents;
close(FILE);
What this is doing:
Opening the file for reading, putting the contents of the file into an array(memory) called @contents.
We create a variable to keep count and we set it's value to 0. Then, start a loop that pulls out each line for analyzing. We assign the variable $line to each line. We need to remove the newline characters (\n) from each line, so we use the chomp command. Then we itenerate the count using ++.
Now we find out what line we are on by checking where our our count is. Then we simply leave out of our new array waht we don't want and print it back to a file.
Chris Ellenburg,
webmaster@wfmy.com
------------------
WFMY-TV Webmaster
[This message has been edited by Chris071371 (edited November 20, 1999).]