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

235Beginner needs help! Writing to file using Perl...

Expand Messages
  • Angi
    Apr 9, 2000

      I should mention that I am a beginner. I would also like
      to apologize if anyone has seen this message already, as
      I posted on a few other lists as well. I am on an NT server,
      running Perl 5.

      Although it appears that the script works, there are no
      errors, and the redirection works as planned. LWP::Simple;
      does work. I was able to print the page to the screen. I
      want to print it to a file instead of the page. The file
      it should print to (and the url to grab) is being sent
      via a form. The file does exist. I hope that someone can
      offer some suggestions. BTW, I also tried entering the actual
      filename and a line of text to write to the file, just to
      test it, and it did not work either. My file remains blank!

      Here is the code I am using:


      use LWP::Simple;
      $URL = $INPUT{'url'};
      $TEMPFILE = $INPUT{'tempfile'};
      $KEYW1 = $INPUT{'keyw1'};
      $KEYW2 = $INPUT{'keyw2'};
      $KEYW3 = $INPUT{'keyw3'};
      $REDIRECTURL = 'testred.asp';
      $ERRREDIRECTURL = 'metalyzerr.asp';
      $CONTENT = get($URL);

      if (head($URL)) {

      print "Location: $ERRREDIRECTURL\n\n";

      } else {

      open (HANDLE, ">>$TEMPFILE");
      print HANDLE $CONTENT;
      close (HANDLE);
      print "Location:



      sub get_form {
      read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
      @pairs = split(/&/, $buffer);
      foreach $pair (@pairs) {
      ($name, $value) = split(/=/, $pair);
      $value =~ tr/+/ /;
      $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
      if ($INPUT{$name}) { $INPUT{$name} = $INPUT{$name}.",".$value; }
      else { $INPUT{$name} = $value; }

      Thank you in advance,

      Angi [mailto:angib@...]