Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

RE: Get those parameters without CGI.pm

by Ovid (Cardinal)
on Jun 21, 2000 at 07:17 UTC ( [id://19157]=note: print w/replies, xml ) Need Help??


in reply to Get those parameters without CGI.pm

This is an example of why the best Perl books say we should stick with Lincoln Stein's CGI module rather than try to write this ourselves.

The above code, aside from reinventing the wheel, has a variety of problems. The most immediately obvious one is the following section of code:

foreach $form (@form_data){ (my $one, my $two) = split(/=/, $form); if ($one =~ m/\+/){ $one =~ s/(\+)/" "/eg; } if ($two =~ m/\+/){ $two =~ s/(\+)/" "/eg; } $one =~ s/%([\da-fA-F][\dA-Fa-f])/pack("C", hex($1))/eg; $two =~ s/%([\da-fA-F][\dA-Fa-f])/pack("C", hex($1))/eg; $form{$one} = $two; $params{$one} = $two; }
This code is duplicated! It should be a subroutine.

If you are going to reinvent the wheel, you should only do so when you are really comfortable with the language in question. Otherwise, these problems creep in and later down the road, when you're still using your reinventions, you'll come back to them and find they need to be rewritten to get around issues like this.

And why are the hashes %forms and %params duplicated? The way they're created above, they are identical. I could go on, but that's enough for now.

Cheers!

Replies are listed 'Best First'.
RE: RE: Get those parameters without CGI.pm
by j.a.p.h. (Pilgrim) on Jun 22, 2000 at 05:04 UTC
    No, %form and %params are not identical. %form contains (of course) the form data submitted with the users request. %params contains %cookie and %form. If there is a param with the same name in both hashes, it's overwritten by %form. However, if you know you want the value from the cookie, and a form was submitted with the same param, you can still get it from the %cookie hash.

    And thank you for your suggestion on how I could make the code better (instead of just telling me that it was flawed and not telling me anything useful).

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (3)
As of 2024-04-19 21:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found