Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

I think this is the wrong forums but I am not sure where to ask

by pccenterllc (Initiate)
on Jul 19, 2010 at 14:22 UTC ( #850264=perlquestion: print w/ replies, xml ) Need Help??
pccenterllc has asked for the wisdom of the Perl Monks concerning the following question:

I am writing a lost and found program that runs on a website and calls a PERL program to process the information into a data base. My problem is that when I click submit the PERL program doesn't run. Before I reloaded my computer it use to run, but I had the wrong code so it didn't do what I wanted. Now I think I have the right code but it won't run. If I double click the .pl file it runs and creates a .txt file with new lines in it. So I know PERL runs on my computer. As I said I think I am asking in the wrong forums but I don't know who or what to ask to get the help I need.

Here is the HTML form tag

 <form id="found" name="found" action="lost.pl" enctype="multipart/form-data" method="post">

Here is what I have so far for my PERL program code. I am not asking for help on the code for my program, as I am using this project to better learn PERL. I just need to know why it isn't running

#!/usr/bin/perl # Get Form Variables sub parse_form { read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); if (length($buffer) < 5) { $buffer = $ENV{QUERY_STRING}; } @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; $FORM{$name} = $value; } } #end parse_form &parse_form; open (LOST, ">>lost.txt")or die "Cannot open lost.txt"; foreach $key (keys %FORM){ print LOST "$key $FORM{$key}+"; } print LOST "\n";

Comment on I think this is the wrong forums but I am not sure where to ask
Select or Download Code
Re: I think this is the wrong forums but I am not sure where to ask
by Anonymous Monk on Jul 19, 2010 at 14:39 UTC
Re: I think this is the wrong forums but I am not sure where to ask
by linuxer (Deacon) on Jul 19, 2010 at 14:41 UTC

    So you're running the program in CGI context? What does the error_log of the web server tell you?

    Some hints about your code:

    • use strict and warnings; they support you with your development
    • use the CGI module to obtain the given parameters.
    • print a valid html header and a short message to STDOUT at the end of the script to prevent "internal server error", because no data was sent.

    untested example

    #! /usr/bin/perl use strict; use warnings; use CGI; my $lost_file = "/FULL/path/to/lost.txt"; my $cgi = CGI->new; open LOST, '>>', $lostfile or die "open(>>) $lostfile failed: $!\n"; for my $param ( $cgi->param ) { print LOST "$param ", $cgi->param($param), "+"; } print LOST "\n"; print $cgi->header('text/plain'), "job is done.\n";

    updates

    • fixed typo in code: s/->new/->param/ in head of for-loop
Re: I think this is the wrong forums but I am not sure where to ask
by roboticus (Canon) on Jul 19, 2010 at 14:42 UTC

    pccenterllc:

    Since perl is running on your machine, you should visit the help forum for your web server software. It sounds like it could be a web server configuration issue.

    ...roboticus

Re: I think this is the wrong forums but I am not sure where to ask
by SuicideJunkie (Priest) on Jul 19, 2010 at 14:46 UTC

    The first thing to learn about Perl is to always throw in

    use strict; use warnings;
    at the top of your programs. It will save you a LOT of trouble.

    If the error messages aren't obvious to you, then add use diagnostics as well.

    Additionally, you should keep a "test.pl" file around so that you can try out any command you're not completely sure of in an isolated environment where you know there are no other errors.

    PS: oh, and if it seems like it just doesn't run, try running it from a command prompt window. That way, the window won't vanish before you can read the compile error messages. ;)

Re: I think this is the wrong forums but I am not sure where to ask
by ikegami (Pope) on Jul 19, 2010 at 14:50 UTC

    You're parsing the reply as if it was a application/x-www-form-urlencoded response, but it's a multipart/form-data response. Use the CGI module.

Re: I think this is the wrong forums but I am not sure where to ask
by pccenterllc (Initiate) on Jul 19, 2010 at 16:40 UTC

    Thanks for all of the advice. I will remove the enctype from my form tag for now as I am just trying to create a flat file DB at this time.

    Once I understand the basics of what I am trying to do I will be changing things to use more efficient code. But if I can't even get the basics down there is no way I'll be able to use the more advanced stuff.

    As to my problem, I think you have answered it. I am using a windows XP system and writing the program on that. I do not believe it is set-up for webserver capabilities. I recently reinstalled XP after an infection and a hardware problem and am leery about what may make my system vulnerable. So now I have to see what I need for a webserver.

    Thank You

      Thanks for all of the advice. I will remove the enctype from my form tag for now as I am just trying to create a flat file DB at this time.

      If you remove that attribute from your form tag, your form will default to application/x-www-form-urlencoded, according to the specs.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://850264]
Approved by Corion
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (9)
As of 2014-07-30 20:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (240 votes), past polls