#!/usr/local/bin/perl use strict; use CGI ':standard'; print "Content-type: text/html\n\n"; my @array; # this opens the original file and sets up the # external file as an array open (FILE,"external_file.txt"); @array = ; close(FILE); # initializes loop count at 0 my $count = 0; #loops through the array (used to be the external # file) foreach (@array) { # the number (3 in his case) corresponds to the # line number where you want to add the #statement in quotation marks if ($count == 3) { #adds the statement in parenthesis to the array #(file) using the concatenation operator (the #period) $_ = $_ . "my newline goes here\n"; #use this line if you want to add a space before #the newline # $_ = $_ . "\nmy newline goes here\n"; #this prints the entire array (with the line #added) to a temporary file open (FILE,">>external.txt"); print FILE @array; close (FILE); #this renames the temporary file to the original #file name but with new line added rename ("external.txt","external_file.txt"); exit; } #endif #loop counter $count++; } #endforeach # exits the program just in case there are less # than the specified number of lines in # the original external file,if ($count == x) exit;