From: David test testingFrom: David test testingFrom: David test testingFrom: David test testingFrom: David test testingFrom: David test testingFrom: David test testingFrom: David test testingFrom: David test testingFrom: David test testingFrom: David test testingFrom: David test testingFrom: David test testingFrom: David test testingFrom: David test testingFrom: David test testingFrom: David test testingFrom: David test testingFrom: David test testing #### #!/usr/bin/perl -w # news.pl # Attempt #3 at a news script. # Use the 'strict' switch to ensure logical operation of the code. #use strict; # Make use of the CGI module. use CGI qw(:standard); use CGI::Carp 'fatalsToBrowser'; # Initialise variables for the data previously inputted. my $nickname = param("nickname"); # Nickname my $headline = param("headline"); # Headline my $news_text = param("news_text"); # News Item Text # Create a variable to store the location of the display page, "index.html". my $old_news = "../html/index.html"; # Read the current data or die with an error message. open (NEWS, "<$old_news") || die "$!"; # Read the data from '$old_news' into an array called '@news'. my @news = ; # Close the '$old_news' file after use. close (NEWS); # Re-open the '$old_news' file for the input of the new data. open (NEWS, ">$old_news") || die "$!"; # Write the data back into the '$old_news' file with the new data included where appropriate. # Loop through each line of the '$old_news' file and write it back. #my $line = ""; foreach $line (@news) { # Add the 'nickname' of the poster. print NEWS "From: $nickname\n"; # Add the 'headline' of the post. print NEWS "$headline\n"; # Add the 'news_text' underneath the 'headline'. print NEWS "$news_text"; } # Close the '$old_news' file after use. close (NEWS); # Provide the poster with a link to their news item. print header(), start_html, h2("Thank you, $nickname"), h4("Go here to view your news item: index.html"), end_html; # EOF news.pl