1. Save the file as textwriter.pl in the PERLSCRIPTS folder.

    Here's what the relevant lines in this script do:
  • $mycomments = $request{"comments"};

    Requests the text entered in the text area named comments in textwriter.html, then assigns it to the variable $mycomments.

  • $myfile = $request{"filename"};

    The form in textwriter.html has a hidden text field named filename. Here the script requests the value assigned to it in the form—textthought.txt—then assigns that value to the variable $myfile.

  • open(MYFILE,">$myfile");

    The Perl command open opens the MYFILE file variable. Then, the > sign tells the Web server that the value of $myfiletextthought.txt—can be overwritten.

    If textthought.txt does not exist, the Web server will create the file. If it does exist, then the old file will be completely overwritten with the new data.

    TIP: When using the open() command, there are three ways a file can be opened:

    > Overwrites an existing file—all previous data is lost
    >> Appends data to the end of an existing file
    < Used for reading data as an input file