in reply to Skip a line

Presuming you mean *write* you can't skip lines per se. When you open a file with > it overwrites any existing data. When you open a file using >> it appends to the end of the file. These are your choices. If you want to 'skip' the first line, presumably to save it, you will need to read it in, save it, open the file for overwrite, write out the saved first line, then write out the rest of the data.

cheers

tachyon

s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

Replies are listed 'Best First'.
Re: Re: Skip a line
by lisaw (Beadle) on Nov 11, 2002 at 19:02 UTC
    Hello, When making the change from opening a file by > to >>, I am finding that when adding info to the file all data lines are being copied and rewritten. So I end up with multiple entries of same line being written every time an addition is made. Any way around this?

      >> appends or in other words ADDS TO THE END OF the existing file. All the data lines are not being copied, they are simply being left there and new data added to the end. Here is a guide for you:

      my $file = '/foo/file.txt'; open IN, $file or die "Can't read $file perl says $!\n"; my @lines = <IN>; close IN; for my $line (@lines) { # do stuff with the lines } # rewrite the file in its entirity open OUT, '>$file' or die "Can't write $file perl says $!\n"; print OUT $line[0]; # print out the first line from the old fil +e print OUT @other_stuff; # print whatever else you want close OUT;

      cheers

      tachyon

      s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print