form POST string parser

form POST string parser

am 07.09.2011 02:15:53 von Rajeev Prasad

--0-224022210-1315354553=:34792
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable

hi,  =0Awhich of the two is better? thx.  =0A$value =3D~ s/%([a-fA-=
F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;  =0Aor=0A$value =3D~ s/%(..)/c=
hr(hex($1))/ge; in both cases if the input string has \ in it, it is b=
eing converted to \\    =0Ai read...=0Achr =  function is used =
to convert ASCII or Unicode values into their equivalent characters...=0Apa=
ck =3D here to convert hex to character ("C")...
--0-224022210-1315354553=:34792--

Re: form POST string parser

am 07.09.2011 02:24:02 von Uri Guttman

>>>>> "RP" == Rajeev Prasad writes:

RP> hi,
RP> =A0
RP> which of the two is better? thx.
RP> =A0
RP> $value =3D~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
RP> =A0
RP> or
RP> $value =3D~ s/%(..)/chr(hex($1))/ge;

both are bad because parsing your own http data is a bad thing. it has
little gotchas all over. use one of the several modules (CGI.pm and
others) that do this for you. they do it correctly and cover all the
little corner cases.

uri

--=20
Uri Guttman -- uri AT perlhunter DOT com --- http://www.perlhunter.com =
--
------------ Perl Developer Recruiting and Placement Services -----------=
--
----- Perl Code Review, Architecture, Development, Training, Support -----=
--

--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/

Re: form POST string parser

am 07.09.2011 10:57:37 von Rob Dixon

On 07/09/2011 01:15, Rajeev Prasad wrote:
>
> which of the two is better? thx.
>
> $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
>
> or
> $value =~ s/%(..)/chr(hex($1))/ge;
>
> in both cases if the input string has \ in it, it is being converted to \\
>
>
> i read...
> chr = function is used to convert ASCII or Unicode values into their equivalent characters...
> pack = here to convert hex to character ("C")...

I would prefer a combination of the two:

s/%([a-fA-F0-9]{2})/chr hex $1/eg;

or perhaps

s/%([[:xdigit:]]{2})/chr hex $1/eg;

Alternatively, the URI::Escape module provides uri_unescape(), which
will do this for you (in a way almost identical to the first of these
two options).

HTH,

Rob




--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/

Re: form POST string parser

am 07.09.2011 18:34:25 von Rajeev Prasad

--0-1209497292-1315413265=:10113
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable

Uri,  =0Athx. I like that suggestion, i totally missed that earlier. I =
will explore cgi module.     From: Uri Guttman s.com>=0ATo: Rajeev Prasad =0ACc: Perl Beginners ners@perl.org>=0ASent: Tuesday, September 6, 2011 7:24 PM=0ASubject: Re: fo=
rm POST string parser >>>>> "RP" == Rajeev Prasad com> writes: =A0 RP> hi,   RP>   =A0 RP> which of the two is b=
etter? thx.   RP>   =A0 RP> $value =3D~ s/%([a-fA-F0-9][a-fA-F0-9])=
/pack("C", hex($1))/eg;   RP>   =A0 RP> or   RP> $value =3D~ s/=
%(..)/chr(hex($1))/ge; both are bad because parsing your own http data=
is a bad thing. it has=0Alittle gotchas all over. use one of the several m=
odules (CGI.pm and=0Aothers) that do this for you. they do it correctly and=
cover all the=0Alittle corner cases. uri -- =0AUri Guttman=A0 --=
=A0 uri AT perlhunter DOT com=A0 ---=A0 http://www.perlhunter.com --=0A----=
--------=A0 Perl Developer Recruiting and Placement Services=A0 -----------=
--=0A-----=A0 Perl Code Review, Architecture, Development, Training, Suppor=
t ------- --=0ATo unsubscribe, e-mail: beginners-unsubscribe@perl.org=
=0AFor additional commands, e-mail: beginners-help@perl.org=0Ahttp://learn.=
perl.org/
--0-1209497292-1315413265=:10113--

Re: form POST string parser

am 07.09.2011 22:23:44 von Rajeev Prasad

--0-1231420520-1315427024=:55078
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable

how good is: http://search.cpan.org/~zenin/CGI-Validate-2.000/Validate.pm =
 =0Awhich is the best module for=A0validating form data?  =0Acan i=
have some pointers to some good examples please?     From: Ra=
jeev Prasad =0ATo: =0ACc: Perl Beginners l.org>=0ASent: Wednesday, September 7, 2011 11:34 AM=0ASubject: Re: form PO=
ST string parser =0AUri,  =0Athx. I like that suggestion, i totall=
y missed that earlier. I will explore cgi module.     From: Ur=
i Guttman =0ATo: Rajeev Prasad =0A=
Cc: Perl Beginners =0ASent: Tuesday, September 6, 2011 =
7:24 PM=0ASubject: Re: form POST string parser >>>>> "RP" == Rajee=
v Prasad writes: =A0 RP> hi,   RP>   =A0 =
RP> which of the two is better? thx.   RP>   =A0 RP> $value =3D~ s/=
%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;   RP>   =A0 RP> or=
  RP> $value =3D~ s/%(..)/chr(hex($1))/ge; both are bad because p=
arsing your own http data is a bad thing. it has=0Alittle gotchas all over.=
use one of the several modules (CGI.pm and=0Aothers) that do this for you.=
they do it correctly and cover all the=0Alittle corner cases. uri=0A=
=0A-- =0AUri Guttman=A0 --=A0 uri AT perlhunter DOT com=A0 ---=A0 http://ww=
w.perlhunter.com --=0A------------=A0 Perl Developer Recruiting and Placeme=
nt Services=A0 -------------=0A-----=A0 Perl Code Review, Architecture, Dev=
elopment, Training, Support ------- --=0ATo unsubscribe, e-mail: begin=
ners-unsubscribe@perl.org=0AFor additional commands, e-mail: beginners-help=
@perl.org=0Ahttp://learn.perl.org/
--0-1231420520-1315427024=:55078--

Re: form POST string parser

am 08.09.2011 08:23:14 von Shlomi Fish

Hi Rajeev,

On Wed, 7 Sep 2011 13:23:44 -0700 (PDT)
Rajeev Prasad wrote:

> how good is: http://search.cpan.org/~zenin/CGI-Validate-2.000/Validate.pm

I never used it.

>  
> which is the best module for validating form data?
>  

Well, I don't know about the best module globally , but at a previous
workplace, we had a bad experience with
http://search.cpan.org/dist/HTML-FormHandler/ (trying to use it in a Cataly=
st application we wrote), and ended up converting
the code to use http://search.cpan.org/dist/HTML-FormFu/ instead. HTML-Form=
Fu
is not too bad from my experience.

> can i have some pointers to some good examples please?

You should be able to find them in HTML-FormFu's distribution as code sampl=
es
in the .pod files, as tests in t/**/*.t, or as standalone examples in the
distribution. There are also some in https://github.com/shlomif/catable and=
in
other Catalyst apps that use FormFu.

Regards,

Shlomi Fish

>  
>  
>=20
> From: Rajeev Prasad
> To:=20
> Cc: Perl Beginners
> Sent: Wednesday, September 7, 2011 11:34 AM
> Subject: Re: form POST string parser
>=20
>=20
> Uri,
>  
> thx. I like that suggestion, i totally missed that earlier. I will explor=
e cgi module.
>  
>  
>=20
> From: Uri Guttman
> To: Rajeev Prasad
> Cc: Perl Beginners
> Sent: Tuesday, September 6, 2011 7:24 PM
> Subject: Re: form POST string parser
>=20
> >>>>> "RP" == Rajeev Prasad writes:
>=20
>   RP> hi,
>   RP>  
>   RP> which of the two is better? thx.
>   RP>  
>   RP> $value =3D~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
>   RP>  
>   RP> or
>   RP> $value =3D~ s/%(..)/chr(hex($1))/ge;
>=20
> both are bad because parsing your own http data is a bad thing. it has
> little gotchas all over. use one of the several modules (CGI.pm and
> others) that do this for you. they do it correctly and cover all the
> little corner cases.
>=20
> uri
>=20



--=20
------------------------------------------------------------ -----
Shlomi Fish http://www.shlomifish.org/
Original Riddles - http://www.shlomifish.org/puzzles/

Tel Aviv, a functional definition: free parking spaceâ€=90free space.
â€=94 Shachar Shemesh ( http://blog.shemesh.biz/?p=3D435 )

Please reply to list if it's a mailing list post - http://shlom.in/reply .

--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/