Here's another common problem which is trivially solved by Tie::File. How do I add a new record at the beginning of a file instead of at the end? unshift @lines, $new; # Or add more than one record #### #################### sub update_threads() { my $parent = $_[0]; my $msg_id = $_[1]; #check if this is a top-level, and set $parent accordingly if ($parent eq 'top') { $parent = $msg_id } my $main_threads_file = $htdocs . $path_info . "/threads.html"; my $archive_threads_file = $htdocs . $path_info . "/posts/" . $date . "threads.html"; my $post_location = $path_info . "/posts/" . $date . "/" . $parent . "_" . $msg_id . ".html"; my $post_name = $parent . "_" . $msg_id; my @threads; my @archive; my $link = "
  • " . $params{"subject"} . " by " . $params{"name"} . " on " . $time . ""; tie @threads, 'Tie::File', $main_threads_file or syslog('err', "update_threads couldn't open file: $main_threads_file"); if ($parent == $msg_id) { unshift @threads, $link; } untie @threads; return; } ## end sub update_threads() #*************************** #### main::get_date() called too early to check prototype at /usr/local/apache/cgi-bin/bthreads-perl line 50. main::read_config() called too early to check prototype at /usr/local/apache/cgi-bin/bthreads-perl line 53. main::print_postform() called too early to check prototype at /usr/local/apache/cgi-bin/bthreads-perl line 63. main::read_mcount() called too early to check prototype at /usr/local/apache/cgi-bin/bthreads-perl line 90. main::get_date() called too early to check prototype at /usr/local/apache/cgi-bin/bthreads-perl line 92. main::generate_post() called too early to check prototype at /usr/local/apache/cgi-bin/bthreads-perl line 95. main::update_threads() called too early to check prototype at /usr/local/apache/cgi-bin/bthreads-perl line 98. main::get_date() called too early to check prototype at /usr/local/apache/cgi-bin/bthreads-perl line 50. main::read_config() called too early to check prototype at /usr/local/apache/cgi-bin/bthreads-perl line 53. main::print_postform() called too early to check prototype at /usr/local/apache/cgi-bin/bthreads-perl line 63. main::read_mcount() called too early to check prototype at /usr/local/apache/cgi-bin/bthreads-perl line 90. main::get_date() called too early to check prototype at /usr/local/apache/cgi-bin/bthreads-perl line 92. main::generate_post() called too early to check prototype at /usr/local/apache/cgi-bin/bthreads-perl line 95. main::update_threads() called too early to check prototype at /usr/local/apache/cgi-bin/bthreads-perl line 98. Use of uninitialized value in read at /usr/lib/perl5/5.6.1/Tie/File.pm line 699. Use of uninitialized value in read at /usr/lib/perl5/5.6.1/Tie/File.pm line 699. Use of uninitialized value in read at /usr/lib/perl5/5.6.1/Tie/File.pm line 699. Use of uninitialized value in read at /usr/lib/perl5/5.6.1/Tie/File.pm line 699. Use of uninitialized value in read at /usr/lib/perl5/5.6.1/Tie/File.pm line 699. Use of uninitialized value in read at /usr/lib/perl5/5.6.1/Tie/File.pm line 699. Use of uninitialized value in read at /usr/lib/perl5/5.6.1/Tie/File.pm line 699. Use of uninitialized value in read at /usr/lib/perl5/5.6.1/Tie/File.pm line 699. Use of uninitialized value in read at ## and so on