Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re^2: CGI Post query

by ant (Scribe)
on Jul 05, 2006 at 09:53 UTC ( #559280=note: print w/replies, xml ) Need Help??


in reply to Re: CGI Post query
in thread CGI Post query

Thanks, for the advice, I took a look at the CGI documentation that you had linked and it covers putting forms into a hash with this piece of code
use CGI ':cgi-lib'; my $params = Vars; print $params->{user};
I used the other method a few years ago and although I never encountered any problems with it, this way I think is much better with the same results.
It's good to learn something new everyday!

Replies are listed 'Best First'.
Re^3: CGI Post query
by merlyn (Sage) on Jul 05, 2006 at 14:20 UTC
    You should unlearn this one though... it will come to bite you when you are using checkboxes or select-multiple option boxes. Understand that there can be multiple values for a given param, and simply ask for them as you need them. I really don't see what's so hard about:
    my $last_name = param('last_name'); # only one last name ... my @colleges_attended = param('colleges_attended'); # possibly 0 or ma +ny colleges attended
    That is, asking for it as you need it. Why does everyone wanna keep copying it into a hash? (It boggles me.)

    -- Randal L. Schwartz, Perl hacker
    Be sure to read my standard disclaimer if this is a reply.

      Hi
      You asked why place the form into a hash?
      The Perl program uses 6 Perl Modules, collects information from about 60 fields and then makes calls to the other modules to enter and retrieve information from databases, check data constraints, etc. Presently the code calls one param at a time and then passes upto a dozen scalar variables to the various other procedures in different modules.
      There are no checkboxes or radio buttons, and currently there are no plans for any files to be uploaded, and this probally won't change in the future.
      It just seemed easier to load the form into a hash and then pass the reference of the hash around all the different modules to access all the various parts of the form, rather than have having vast amount of scalar variables declared all over the different modules .
      But perhaps I'm wrong, it won't be the first time ;-)
      Any more thoughts on this would be great.
      Ant

        If you are passing the values of the parameters around in your program you might want to consider using the OO interface to CGI and pass the CGI object around instead and use $cgi->param() in the subroutines. This has the side benefit that if you find that you require more parameters in a subroutine you won't need to change the arguments.

        /J\

Re^3: CGI Post query
by cowboy (Friar) on Jul 05, 2006 at 17:58 UTC
    I would second the advice above about not rolling your own. Ovid has a nice explanation of ways rolling your own can bite you in his online cgi course here

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://559280]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (3)
As of 2023-02-06 06:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I prefer not to run the latest version of Perl because:







    Results (33 votes). Check out past polls.

    Notices?