u914 has asked for the wisdom of the Perl Monks concerning the following question:
I've poked around a good bit, and futzed a lot with this, to no avail, so..... here's the question.
Looking at this node, i'm told that it's pretty easy to add a line to the beginning of a file:
Pretty much the same thing is said in the Tie::File podHere'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
My problem is that my code (below the readmore) appears to:
What do i want? I want to have the line in question inserted at the beginning of the file, as described in the quote/outtake above. It seems obvious that i'm doing something wrong, but i can't figure out what. I've pasted the offending sub below (yes, the script is running with -w), as well as some the STDERR output.
Thanks greatly for your attention!
the STDERR Below (can i nest readmore tags? hmmm) is the full output to the STDERR during one run... i know much of it is irrelevant, and i strongly suspect that the Tie::File errors are irrelevant too, but i'm not sure...#################### 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 = "<li> <!-- mid=\"$post_name\" --> <a href=\"$post_location\ +">" . $params{"subject"} . "</a> by " . $params{"name"} . " <font si +ze=\"-1\">on " . $time . "</font>"; 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() #***************************
anyhow,
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
update (broquaint): changed <pre> tags to <code> and dropped a chunk of repeated error messages
|
|---|