# The next page of the story exists (and hasn't snuck in # while we were writing a different new page). # Read it in and display it. if (!(open(STORY, "<$nextfile"))) { print "Could not open file $nextfile to read it!
\n"; } else { # Read data from story file: $author_name = ; $author_email = ; $chapter_title = ; $next_text_1 = ; $next_text_2 = ; chomp($author_name); chomp($author_email); chomp($chapter_title); chomp($next_text_1); chomp($next_text_2); $chapter = 1 + $in{'chapter'}; print "Chapter $chapter: $chapter_title

\n"; if (($author_name ne "") || ($author_email ne "")) { $author = "$author_name $author_email"; } else { $author= "an anonymous author"; } print "

this page added by $author

\n"; while () { print $_; } $next_num_1 = 2 * $in{'next'}; $next_num_2 = $next_num_1 + 1; # Do some fancy formatting on the chapter numbers, so that they # don't print out in scientific notation. This only becomes # important when users enter chapters more than 50 levels deep. !!! $next_num_1 = format_chapter_number($next_num_1); $next_num_2 = format_chapter_number($next_num_2); print <


What do you do now?

$next_text_1
$next_text_2

EOF } } elsif ($in{'submit'} eq "") { # The next page of the story doesn't exist. # Ask the user to enter it. print <Your Turn You have reached the end of the story action.

Now it's your turn to enter what happens next in the story.

Your name: (optional)

Your email address: (optional)


The next part of the story:


The two things the reader can do next:
Option One:
Option Two:

A title for your chapter:


EOF } else { # The user has entered a next page. # See if it's okay. If it is, save it. # Convert newlines to
html in the story: $in{story_text} =~ s/\n/
\n/gio; # Don't let people create any old file: $prev_page_num = format_chapter_number(int($in{'next'} / 2)); if (($in{'next'} ne "1") && (! -e "$story_dir/$prev_page_num.txt")) { print "Invalid chapter name!
"; # Check for any missing text: } elsif ($in{story_text} eq "") { print "Please write the description of what happens now.
"; print "Press your browser's 'Back' button to add it."; } elsif (($in{next_text_1} eq "") || ($in{next_text_2} eq "")) { print "Please enter two options for what the user can do next.
"; print "Press your browser's 'Back' button to add this."; } elsif ($in{chapter_title} eq "") { print "Please enter a title for your chapter.
"; print "Press your browser's 'Back' button to add it."; } else { # Make sure file is still available. if (-e $nextfile) { print <Ooops! Someone else entered this section of the story while you were typing. I can't enter your section.

See it

After you select the "See it" link, you may need to press the 'Reload' button on your browser to see what the other person entered.

EOF } else { # Save it! if (!open(STORY, ">$nextfile")) { print "Oh oh. I couldn't open the file '$nextfile' to save your section. (Error: $!) So I didn't save it.\n"; } else { print STORY "$in{author_name}\n"; print STORY "$in{author_email}\n"; print STORY "$in{chapter_title}\n"; print STORY "$in{next_text_1}\n"; print STORY "$in{next_text_2}\n"; print STORY "$in{story_text}\n"; close(STORY); print <