in reply to CGI Server Error

Newbie question here (so please go easy on me).. Could someone tell me why nothing happens when I access this script through my browser? Ultimately, I want to read an html file into my browser, edit and/or append to the file, and save the changes. So far, I just get a blank screen.
#!/usr/local/bin/perl use strict; use CGI::Carp qw(fatalsToBrowser); print "Content-type: text/html\n\n"; my $file = "new_guestbook.html"; open(F,"+< $file") or die "Could not open $file: $!"; my @file = <F>; s/date/localtime/eg for @file; seek F,0,0 or die "Could not seek in $file: $!"; truncate F,0 or die "Could not truncate $file: $!"; print F @file; close F;

Replies are listed 'Best First'.
(tye)Re: file opening question
by tye (Sage) on Jul 04, 2001 at 01:37 UTC

    You forgot print $file; which sends the modified contents to the browser. Your code modifies the file but never sends anything other than the header to the browser.

            - tye (but my friends call me "Tye")

      Unusual to be able to correct tye but you actually need print @file to print the file contents as $file is just the file name. To clarify print F @file goes to the file handle we have opened called <F>. print @file goes to the default file handle (in this case STDOUT) which is what gets sent to the browser.

      tachyon

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

        So is everyone saying that this script should work in theory? Because nothing is getting sent to the browser in either case.
Re: file opening question
by voyager (Friar) on Jul 04, 2001 at 01:37 UTC
    Do you mean the file update doesn't happen, or that you don't see anything in your browser?

    Other than the http header, you're not sending anything to the browser.