well im still learning to use perl and i wanted to develop a small cgi that could accomplish many tasks all in one, as an excercise. using code samples and making them workable, code snippets, and alot of my own i built the following cgi <
The CGI >. its to be a base framework for me to add alot more features to it. however i cant seem to find what i did wrong, might be something small but i dont notice it, when run through perl itself it says everything is fine. but when accessed through a web server it returns param on line 78 is undefined, which is in a subroutine ... and the reason why its undefined is cause that subs job is to define them, its like its reading into the sub befor allowing it to do its function ... would appreciate any help that people could provide me with to make it function properly.
## UPDATE ##
used strict and warnings
# output :
they both returned on variables at the head of the application that were declared for later definition in the code ... reporting that essentially they hadnt been called anywhere. But they are later in the scripting, predeclaration of variables i noticed isnt uncommon in perl ... if i predeclare that $my_shoes = 'your shoes'; print $my_shoes; itll do its function ... so predeclaring variables for later use in the script isnt a problem. actually this was all working as i was using scripting to parse the data on my own without CGI.PM, then i decided to port the script over to it , those variables worked fine under the old scripting , but the main problem is it references only one error type in the script and that is ....
if ($USE_CGI_MODULE == 1) {
use CGI;
$\ = "\n";
$req = new CGI;
print $req->header;
&read_fields;
}
else {
# cgi process variables here if CGI.PM is not available
}
sub read_fields {
my(%fields);
foreach $f ($req->param) {
$name = &clean_name($f);
$fields{$f}{name} = $name;
$value = &clean_value($f);
$fields{$f}{value} = $value;
}
return(%fields);
}
sub clean_name {
local($f) = shift;
$f =~ s/^F\d+_//;
$f =~ s/_/ /g;
return($f);
}
sub clean_value {
local($f) = shift;
local(@val, $val);
@val = $req->param($f);
$#val-- unless $val[-1] =~/\S/;
$val = join(" - ", @val);
}
now its error exists under the subroutine read_fields.
foreach $f ($req->param)
returns that param is undefined. but if you look its defining value comes from the submitted form, so it will be undefined til a form is submitted ... why is it reading into the subroutine in that fashion when it has the data to define that section.
As for CGI:Carp qw/fatalsToBrowser/;
i used it to see what it would do but ... i dont want to use something of that nature, im wanting the script to return its own error warnings. at present it is simplistic, but wanting to develop it further. I will however keep that in mind when testing CGI scripts, because it does report some nice things. On my script it reported only things that were predeclared and not set anywhere,not anything serious. So thanks to suggesting it.
strict and warnings
On my script it reported only things that were predeclared and not set anywhere.
But did return that param was undefined
so on final take from those 3 :
predeclaration on variables later defined in the script is ok
this even being a direct declaration to reading the submitted form to defining param, its returning undefined in sub return_fields. well like i said if the form is submitted it has the defined values so why is it reading into the sub and undefining it, when it has the data to define it being sent.
same error only that one remains. im stumped why the data to be defined is getting undefined, or is it that its reading the sub and finding its undefined and not even bothering with the submitted data that will define it. will look into it more over the week and try some things ... if not ill revert back to my own cgi processing subs that worked before.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.