Ron Brinkman wrote:
> FORM data from a web client does not contain newline characters.
>
> Feedback from the client arrives in a "URL encoded" format where:
> * Special characters (!@#$%^&* etc.) are hexified (# is turned into %23, for example)
> * The space character is turned into a "+" character
> * The FORM entries are grouped into name/value pairs.
> * The name/value pairs are separated from each other by the "&" character
> * The name and value are separated from each other by the "=" character
> * stdin contains the whole (sometimes very long) string
>
> For example, if I have a FORM which asks for the user's name and address and the
>user responded:
> Name: Bill Clinton
> Address: 1600 Pennsylvania Apt #4
> it might arrive in stdin looking like:
> name=Bill+Clinton&address=1600+Pennsylvania+Apt+%234
>
> I normally use the POST method to send data from the client to the server.
> You could try the following perl code to decode this input:
>
> if ($ENV{'REQUEST_METHOD'} eq 'POST') {
>
> read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
>
> @pairs = split(/&/, $buffer);
> foreach $pair (@pairs) {
> ($name, $value) = split(/=/, $pair);
> $value =~ tr/+/ /;
> $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
> $FORM{$name} = $value;
> }
> .
> .
> .
> }
>
> The result in this case will be two hash values defined:
> $FORM(name) = "Bill Clinton";
> $FORM(address) = "1600 Pennsylvania Apt #4";
>
> Good luck,
> Ron Brinkman
>
> -----Original Message-----
> From: Bill Carlson [SMTP:[EMAIL PROTECTED]]
> Sent: Wednesday, September 06, 2000 8:20 AM
> To: [EMAIL PROTECTED]
> Subject: Re: [OT] perl question [answered]
>
> On Wed, 6 Sep 2000, Bret Hughes wrote:
>
> > Thanks for the tips guys. As I was looking at my code, I
> > realied that I had not actually tried the combination that I
> > posted. What i did try was:
> >
> > @resarray= split /"\n"/, $resstring;
> >
> > Which for some reason I can not discern, puts everything
> > (multiple lines) in the first element of the array. If some
> > one would care to educate me on why that is I relly would like
> > to know. I thought the " allowed interpolation of the special
> > backslashed chars.
>
> Bret,
>
> You don't need the quotes in a regex expression. The string is in the
> first element of the array because your expression didn't match anything,
> ie there are no sequences "\n" in the string. You want:
> @resarray = split /\n/, $resstring;
>
> Now, whether that actually does what you want depends on what is in
> $resstring to begin with. You might try running the app with perl in debug
> mode (a good thing to learn).
>
> HTH,
>
> Bill Carlson
>
Thanks guys I got it working. What I was doing was POSTing a form from the client
side and wanted
to parse out the resulting html page returned into seperate lines so I could buzz the
file for a
line with a specific value and then parse some of the information on that line into a
variable to do
some other stuff with. Works pretty neat.
FWIW I was verifiing zipcodes for addresses in our database using the usps.com site
to look them
up. A pretty good excersie in perl and the use of several object contained in a
couple of different
perl modules. The test ran through about 250 addresses in just a few minutes. Not we
have the zip+4
area codes !
Thanks again for your help.
Bret
_______________________________________________
Redhat-list mailing list
[EMAIL PROTECTED]
https://listman.redhat.com/mailman/listinfo/redhat-list