
Angi_28_CA
Deleted
Apr 8, 2000, 10:51 PM
Post #1 of 2
(412 views)
|
|
Beginner needs help writing to file using Perl...
|
Can't Post
|
|
Hi, 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 boards 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: #!/perl/bin/perl use LWP::Simple; &get_form; $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: $REDIRECTURL?url=$URL&filename=$TEMPFILE&keyw1=$KEYW1&keyw2=$KEYW2&keyw3=$KEYW3\n\n"; } exit; 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
|