Loading ...
Sorry, an error occurred while loading the content.

The file sample.txt could not be found

Expand Messages
  • Jeff
    Hi I have copied this HTML document and the cgi reply from different sources. I have been reading my Perl for Dummies book for days but can t make it work
    Message 1 of 3 , Nov 27, 2000
    • 0 Attachment
      Hi
       
      I have copied this HTML document and the cgi reply from different sources.  I have been reading my Perl for Dummies book for days but can't make it work (shows how Dum I am).  Thanks for any help.
       
      Jeff
       
      SUEXEC: Failed to open log file.
      fopen: Permission denied
      The file sample.txt could not be found.
       
      *****************************************
       
      <!doctype html public "-//w3c//dtd html 4.0 transitional//en">
      <html>
      <head>
         <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
         <meta name="GENERATOR" content="Mozilla/4.7 [en] (Win98; I) [Netscape]">
         <title>counter</title>
      </head>
      <body bgcolor="#F5F5DC">
      <!-- counter.htm --><form ACTION="http://www.hyett.com/cgi/counter.cgi" METHOD=POST>
      <center>
      <h2>
      Inna</h2></center>
      <b>Paste your message here:</b>
      <br><textarea ROWS=3 COLS=50 NAME=sample.txt></textarea>
      <p><b>and&nbsp;</b><input TYPE=SUBMIT VALUE="Send"></form>
      </body>
      </html>
       
      **************************************************************
       
      #!/usr/local/bin/perl
      # counter-reply.cgi
       
      $| = 1;
       
      use CGI_Lite;
      $InCGI = new CGI_Lite();
      @FormData = $InCGI->parse_form_data();
       
      # counter1.pl: one way to count the characters, words, and
      #    lines in a text file.
       
      # The name of the file that will be counted
      $TheFile = "sample.txt";
       
      # Open the file but quit if it doesn't exist
      open(INFILE, $TheFile) or die "The file $TheFile could " .
          "not be found.\n";
       
      # Initialize the counters
      $CharCount = 0;
      $WordCount = 0;
      $LineCount = 0;
       
      while(<INFILE>) {
          $TheLine = $_;  # Save the line's contents
          chomp($TheLine);  # Get rid of the line break
          $LineCount = $LineCount + 1;  # This is the easy part!
          $LineLen = length($TheLine);
          # We now know how many characters (minus the line
          #    break) are on this line
          $CharCount = $CharCount + $LineLen;
       
          # Next, do the tricky stuff for counting words on the line
       
          # The line is empty, so we're done
          if($TheLine eq "") { next };
          # The line has at least one word on it
          $WordCount = $WordCount + 1;
          # Now loop through each character on this line
          #    to look for words
          $CharPos = 0;  # Position we are in the line
          # Check for line end; if not, check for a space
          until($CharPos == $LineLen) {
              if(substr($TheLine, $CharPos, 1) eq " ")
                  { $WordCount = $WordCount + 1 }
              $CharPos = $CharPos + 1;
          }  # End of until
      }  # End of while(<INFILE>) loop
      print "Content-type: text/html\n\n";  # output HTML header
      print <<EOF; # Print lines below up to EOF on a line by itself...
      <HTML>
      <HEAD><TITLE> Counter Reply </TITLE></HEAD>
      <BODY BGCOLOR="#AACCAA">
      <H2><CENTER> Inna </CENTER></H2><B>
       
      <BLOCKQUOTE> Number of words:  $WordCount   </BLOCKQUOTE>
       
      </B></BODY></HTML>
      EOF
      # OK, stop printing now.
       
       
       
       
    • webmaster@bmw-club.org.uk
      ... sources. I have been reading my Perl for Dummies book for days but can t make it work (shows how Dum I am). Thanks for any help. ... Jeff, You have mixed
      Message 2 of 3 , Nov 27, 2000
      • 0 Attachment
        --- In perl-beginner@egroups.com, "Jeff" <blackhaw@m...> wrote:
        > Hi
        >
        > I have copied this HTML document and the cgi reply from different
        sources. I have been reading my Perl for Dummies book for days but
        can't make it work (shows how Dum I am). Thanks for any help.
        >
        > Jeff
        >
        > SUEXEC: Failed to open log file.
        > fopen: Permission denied
        > The file sample.txt could not be found.

        Jeff,

        You have mixed code from different sources and ended up with a script
        which gets data a form, but does nothing with the data.

        It tries to open 'sample.txt' but dies with an error, which suggests
        that either the files permissions are not set correctly, or it does
        not exist.

        Have you created the file 'sample.txt' in the same directory as your
        script? Is there anything in the file?

        What are you trying (or wanting) to do with the form data?

        Greg (bmwclub webmaster)
      • webmaster@bmw-club.org.uk
        ... script ... I should also have said that the form (tries to )send data to script counter.cgi , but your action line is wrong, it should read like:
        Message 3 of 3 , Nov 27, 2000
        • 0 Attachment
          --- In perl-beginner@egroups.com, I wrote:

          > Jeff,
          >
          > You have mixed code from different sources and ended up with a
          script
          > which gets data a form, but does nothing with the data.
          >

          I should also have said that the form (tries to )send data to
          script 'counter.cgi', but your action line is wrong, it should read
          like:

          <FORM ACTION="http://www.yoursite.com/scriptname.cgi" METHOD='POST'>
        Your message has been successfully submitted and would be delivered to recipients shortly.