Perl: Modify certain line number in text-file

Just wrote up a small pseudocode for a previous post here.
[sourcecode type="php"]

open (IF, "infile.txt");
open (OF, "outfile.txt");
  while (my $line = <IF>) {
    $count++;
    if ($count == 10) {
      # Modify
      print OF "somethingelse\r\n";
    } else {
      # Don't modify
      print OF $line;
    }
  }
close(OF);
close(IF);

[/sourcecode]

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Discover more from Tedds blog

Subscribe now to keep reading and get access to the full archive.

Continue reading