Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

RE: Get those parameters without

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

in reply to Get those parameters without

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.


Replies are listed 'Best First'.
RE: RE: Get those parameters without
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?

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (5)
As of 2023-09-30 03:19 GMT
Find Nodes?
    Voting Booth?

    No recent polls found