[offtopic]
STOP THE CROSS POSTING MADNESS

you will notice that I removed perl-cgi from this reply. Please use this to
continue the thread.

Thank you

> -----Original Message-----
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
> Sent: Thursday, July 11, 2002 2:01 PM
> To: Connie Chan; [EMAIL PROTECTED]; [EMAIL PROTECTED]
> Subject: Re: What is this string type? How to play with?
> 
> 
> Oops, let me make one small revision to my code:
> 
> if (exists($form_vars{$name})) { # if this is the first of 
> this form input name.
> 
> should be
> 
> if (!exists($form_vars{$name})) { # if this is the first of 
> this form input name.
> 
> Sorry about that all.
> 
> Regards,
> David
> 
> 
> ----- Original Message -----
> From: <[EMAIL PROTECTED]>
> To: "Connie Chan" <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]>; 
> <[EMAIL PROTECTED]>
> Sent: Thursday, July 11, 2002 11:53 AM
> Subject: Re: What is this string type? How to play with?
> 
> 
> Connie,
> 
> > ; has no problem, why you would like to escape( \ )it ?
> I know that = and ; don't have a problem, I escape them 
> because I escape every special character,
> that way I don't have to worry about what I do and don't need 
> to escape.  I know, bad habit (old
> habits die hard).
> 
> > Besides, if you 'next' it if that $variable is not a 
> name=value pair,
> > so is that mean this var will throw away ?
> This is a safety net incase somebody types in the url with 
> something like this:
> http://www.domain.com/test.cgi?namea=valuea&nameb&namec=valuec
> You don't try to split on = when there's not an = in there.
> Trust me, I've put a lot of thought into this code over the 
> last 2 1/2 years.  I don't particularly
> care for CGI.pm either (but we wont go into that), I wrote my 
> own called Form.pm which I hope to get
> up on CPAN one of these days.  It handles both GET and POST 
> as well as command line parameters
> (Along with post [MIME], I also accept files).  It also works 
> on Linux and Windows.  Its also much
> faster than CGI.pm because its strait to the point, the only 
> thing its intended to do is retrieve
> data and give it in a useable format.
> 
> > Hmmm... what is this purpose ? $name is probably going to be a
> > var's name, how come it goes with a blank ? and with an assumption
> > that the $name is coming as a URI escaped string ?
> Well that's exactly what we are doing, unescaping a URI, we 
> just happen to split it into name and
> value before unescaping it (this is important incase somebody 
> has a %26 in their name or value).
> 
> > Just hard to imagine how come a request coming with same name.
> > Aren't we supposing the later come value with same name 
> will overwrite
> > the first one ?
> How about this instance:
> http://www.domain.com/test.cgi?name=joe&prefscheckbox=YesEmail
> Me&prefscheckbox=YesPhoneMe&prefscheck
> box=YesSnailMailMe
> This is a scenario when you want all of the multiple values 
> with the same name, so you need to put
> it into an array instead of a scalar.
> 
> I knew right from when you mentioned $ENV{'QUERY_STRING'} 
> That you were intending to write a form
> input parser.  Well if you are only going to use get, 
> consider the following:
> 
> --------------------------------------------------------------------
> my @variables = split(/[\&\;]/, $ENV{'QUERY_STRING'});
> my %form_vars;
> foreach $variable (@variables) {
>     next if ($variable !~ /\=/);
>     my ($name, $value) = split(/\=/, $variable);
>     $name =~ tr/+/ /;
>     $name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
>     $value =~ tr/+/ /;
>     $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
>     if ($value ne ""){ # remove this if statement if you want 
> to keep pairs where the name has an
> empty value
>         if (exists($form_vars{$name})) { # if this is the 
> first of this form input name.
>             $form_vars{$name} = $value; # setting the 
> variable the hash with the name to the value
>         } else { # for repeated times in with the same form input name
>             $form_vars{$name} = [($form_vars{$name})] if 
> (ref($form_vars{$name} ne "ARRAY")); # make
> this an array if this its not one yet
>             push(@{$form_vars{$name}}, $value); # adding the 
> next element to the list
>         }
>     }
> }
> --------------------------------------------------------------------
>     This essentially gives you a hash with name value pairs 
> for every single value names, and an
> array ref for every name that has multiple values.  
> Basically, it gives you anything that was sent
> (optionally even name empty value sets assuming you remove 
> the if statement around the assignment
> block).
>     Eventually when I get it on CPAN, it will be a simple as
> use Form;
> my %input = Form();
> 
> Anyway, good luck,
> David
> 
> 
> 
> 
> ----- Original Message -----
> From: "Connie Chan" <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]>; 
> <[EMAIL PROTECTED]>
> Sent: Thursday, July 11, 2002 10:59 AM
> Subject: Re: What is this string type? How to play with?
> 
> 
> Hi David,
> 
> Hehe... Thanks in advice. Anyway what I am looking for is making
> those stuff back to what they looks like when they come, that is,  the
> $input in your script...
> 
> However, may I have some questions about your sample ? =)
> 
> > my @variables = split(/[\&\;]/, $input);
> ; has no problem, why you would like to escape( \ )it ?
> 
> >     next if ($variable !~ /\=/);
> = also no problem , why you would like to escape it too ?
> Besides, if you 'next' it if that $variable is not a name=value pair,
> so is that mean this var will throw away ?
> 
> >     $name =~ tr/+/ /;
> >     $name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
> 
> Hmmm... what is this purpose ? $name is probrably going to be a
> var's name, how come it goes with a blank ? and with an assumption
> that the $name is coming as a URI escaped string ?
> 
> >     ...... Keep in mind, you may have multiple
> >     # values for the same name.
> 
> Just hard to imagine how come a request coming with same name.
> Aren't we supposing the later come value with same name will overwrite
> the first one ?
> 
> Maybe I am still new to Perl... so I'm try to write my script 
> to handle a
> form request
> like this ? Would you and the list comment on me ? ( except 
> telling me to
> use CGI,
> because I won't use it unless I have to deal with multipart form =))
> 
> my %data = undef;
> my $input = undef;
> 
> ($ENV{REQUEST_METHOD} eq "POST") ?
> { read (STDIN, $input, $ENV{CONTENT_LENGTH)} :
> { $input = $ENV{QUERY_STRING}} ;
> 
> my @vars = split (/\&/, $input);
> 
> for (@vars)
> { my ($name, $value) = split (/=/, $_);
>     $value=~ tr/+/ /;
>     $value=~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
>     $data{$name} = $value;
> }
> 
> Rgds,
> Connie
> 
> 
> > 
> --------------------------------------------------------------
> ------------
> --
> > my @variables = split(/[\&\;]/, $input);
> > foreach $variable (@variables) {
> >     next if ($variable !~ /\=/);
> >
> >     my ($name, $value) = split(/\=/, $variable);
> >
> >     $name =~ tr/+/ /;
> >     $name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
> >     $value =~ tr/+/ /;
> >     $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
> >
> >     # assignment to some form of a variable structure that 
> you will be
> >     # using out side this loop.  Keep in mind, you may have multiple
> >     # values for the same name.
> > }
> > 
> --------------------------------------------------------------
> ------------
> --
> >
> > Regards,
> > David
> >
> >
> >
> > ----- Original Message -----
> > From: "Connie Chan" <[EMAIL PROTECTED]>
> > To: <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]>
> > Sent: Wednesday, July 10, 2002 4:21 PM
> > Subject: What is this string type? How to play with?
> >
> >
> > Hi all,
> >
> > With get method from form, we always see that the
> > $ENV{QUERY_STRING} like this :
> > &message=%20%2F%15+...&.......
> >
> > btw, what is the name of that string in types of ? Escape ? 
> Unicode ?
> >
> > With simple tr/// and s///, I can get back what exact the input
> > is, but, how can I make a the input back to the.... above format ?
> > Totally have no idea...
> >
> > Rgds,
> > Connie
> >
> >
> >
> >
> > --
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> >
> >
> 
> 
> 
> 
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
> 
> 
> 
> -- 
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 

----------------------------------------------------------------------------
--------------------
The views and opinions expressed in this email message are the sender's
own, and do not necessarily represent the views and opinions of Summit
Systems Inc.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to