Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

RE: still confused with CGI and carriage returns carriage returns

by Keighvin (Novice)
on Apr 26, 2000 at 08:27 UTC ( #9168=note: print w/ replies, xml ) Need Help??


in reply to still confused with CGI and carriage returns carriage returns

I've encountered this problem before, but I wasn't using CGI.pm's extensions: I parsed the input myself with some handy bits:

use CGI qw/:standard/; read(STDIN, $formdata, $ENV{'CONTENT_LENGTH'}); @pairs = split(/\&/, $formdata); foreach $pair (@pairs){ ($name, $value) = split(/=/, $pair); $value =~ tr/+/ /; $value =~ s/%0D%0A/\n/g; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $FORM{$name} = $value; }
The above code runs everything through nice and quick, and if you still want to use your CGI.pm extensions you can (since this doesn't rely on it, you can also omit that line). The beauty of this script is it will read everything in and parse it at once so you don't have to go fishing for any of the values you need. The values you accessed before would now be: $FORM{'FILE1'}, $FORM{'login'}, $FORM{'description'}; Similarly you're free to use a "foreach $key (keys %FORM){};" on this. Enjoy!


Comment on RE: still confused with CGI and carriage returns carriage returns
Select or Download Code
An addendum...
by Keighvin (Novice) on Apr 26, 2000 at 22:32 UTC
    An addendum to my code snippit: It does *not* remove carriage returns, rather it takes the common extra byte that comes with the \n and changes it into *just* a \n. If you still want to get rid of these use =~ tr/\n//; before you pass it into the %FORM.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (11)
As of 2014-12-29 16:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (194 votes), past polls