in reply to file opening question
in thread CGI Server Error

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")

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

    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.

        Hi Anon. This code will/does work

        #!/usr/local/bin/perl use strict; use CGI::Carp qw(fatalsToBrowser); # this is the required header print "Content-type: text/html\n\n"; # this will go to the browser print "<h1>Show me 'Hello World!' the browser window!</h1>" 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; # this rewrites file close F; # this goes to browser, you see nothing if @file is empty print @file

        Run the code above. You will see at least the message in the browser window. If you do not see your file then specify an accurate full path to that file and make sure it is not empty (if you want to see something).

        cheers

        tachyon

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