newbie regular expression questions

B

bbxrider

i' ve found this code for parsing form input
foreach (split(/[&;]/, $buffer)) {
s/\+/ /g ;
($name, $value)= split('=', $_, 2) ;
$name=~ s/%([0-9A-Fa-f]{2})/chr(hex($1))/ge ;
$value=~ s/%([0-9A-Fa-f]{2})/chr(hex($1))/ge ;
..........
i know it works but the data is ascii characters to begin with and don't
understand what is the need for the substitution after converting all the
+'s to spaces??
i know am cycling thru the input field names and their values character by
character for searching for only digits and upper+lower case alphabet
to substitute but
don't understand significance of the % sign,
not really sure what the {2} grouping is doing
and basically it seems to be saying look for ascii digits and alphabet and
convert the hex value of those characters to the same value as starting
with, in other words, convert the original value back to the original
value????????
is type of conversion only necessary due to properties of form input data on
the web????
 
G

Gunnar Hjalmarsson

bbxrider said:
i' ve found this code for parsing form input
foreach (split(/[&;]/, $buffer)) {
s/\+/ /g ;
($name, $value)= split('=', $_, 2) ;
$name=~ s/%([0-9A-Fa-f]{2})/chr(hex($1))/ge ;
$value=~ s/%([0-9A-Fa-f]{2})/chr(hex($1))/ge ;
..........
i know it works but the data is ascii characters to begin with and
don't understand what is the need for the substitution after
converting all the +'s to spaces??

Your questions are not regular expression questions.

Data gets URI encoded when sent to a web server, so it has to be
decoded before used. To get a better understanding of it, you can for
instance study the documentation of URI::Escape:
http://www.perldoc.com/perl5.8.0/lib/URI/Escape.html

Of course, if there are no characters in any of the names and values
besides the restricted set of characters for URI strings, the decoding
does not make a difference. You'd better not count on that, though.
is type of conversion only necessary due to properties of form
input data on the web????

It's necessary when data is submitted through a query string as well.
 
T

Tintin

bbxrider said:
i' ve found this code for parsing form input
foreach (split(/[&;]/, $buffer)) {
s/\+/ /g ;
($name, $value)= split('=', $_, 2) ;
$name=~ s/%([0-9A-Fa-f]{2})/chr(hex($1))/ge ;
$value=~ s/%([0-9A-Fa-f]{2})/chr(hex($1))/ge ;
..........
i know it works

Do you really? How do you know it works if you don't fully understand the
code?
 
G

Gunnar Hjalmarsson

Joe said:
bbxrider said:
i' ve found this code for parsing form input
foreach (split(/[&;]/, $buffer)) {
s/\+/ /g ;
($name, $value)= split('=', $_, 2) ;
$name=~ s/%([0-9A-Fa-f]{2})/chr(hex($1))/ge ;
$value=~ s/%([0-9A-Fa-f]{2})/chr(hex($1))/ge ;
is type of conversion only necessary due to properties of form
input data on the web????

Yes.

No, not only _form_ input.
 
B

bbxrider

thanks for all the help, except from tintin, if thats your idea of help
please just keep it to yourself, it certainly doesn't do anybody any good
however am still struggling with this please see new post
under newbie processing form input question
 
G

Gunnar Hjalmarsson

bbxrider said:
thanks for all the help, except from tintin, if thats your idea of
help please just keep it to yourself, it certainly doesn't do
anybody any good

Tintin's comment was not unhelpful, it was justified, and you really
ought to find it worth considering. IMHO you owe him an apology.
 
A

A. Sinan Unur

thanks for all the help, except from tintin, if thats your idea of
help please just keep it to yourself, it certainly doesn't do anybody
any good however am still struggling with this please see new post
under newbie processing form input question

news:ZqRvb.280961$Fm2.290586@attbi_s04...

Do not top-post.

Do read the posting guidelines posted here regularly and follow them.

Do use Google to locate the CGI specs and read them.

Sinan.
 
B

bbxrider

gunnar,
i would apologize based on your request because i appreciate your thoughtful
and helpful replies
and that engenders my respect for your opinions as well
perhaps i should have stated my dilema that 'it seems to work from the
testing i have done', instead of 'i know it works'
because i did test the code as best i thought and am confused by the
results, i always try to find answers first from my manuals and
then google
as far as coding and testing i think we all come to understand how it works
from both its stated functionality
in documentation and actual testing, i'm new to perl but there are other
languages that i programmed in
for years and still am learing subtle things about even the most common
syntax, functions etc., the point being
we are not perfect, sometimes there is more than we think we know, and
sometimes we seek the help of
others when at a dead end
but thats why i post questions in a forum such as this, obviously if i
understood the code i wouldn't be
asking the question!
i can't know the exact motivation of tintin's comments and if i
misintrepeted, i regret that.
the extent and tone of his reply, solely as written, in IMHO seems to be
questioning
my right to even ask the question
it has a sarcastic tone and it seems to be scolding or demeaning, if thats
all somebody has to say without
any hint of 'maybe you should try this or read this, etc' then i can only
assume they have no real motivation to help.
 
M

Malcolm Dew-Jones

Tintin ([email protected]) wrote:

: : > i' ve found this code for parsing form input
: > foreach (split(/[&;]/, $buffer)) {
: > s/\+/ /g ;
: > ($name, $value)= split('=', $_, 2) ;
: > $name=~ s/%([0-9A-Fa-f]{2})/chr(hex($1))/ge ;
: > $value=~ s/%([0-9A-Fa-f]{2})/chr(hex($1))/ge ;
: > ..........
: > i know it works

: Do you really? How do you know it works if you don't fully understand the
: code?

I know my car works, but I don't fully understand it.

I know my java compiler works but I understand that much less.

I haven't looked at the internal details of CGI.PM in ages, I don't
remember most of its documentation, I forget the _exact_ significance of
the qw:)standard) that I prefer over the object interface, I have never
bothered to figured out certain features that I haven't found the need to
use based on a high level description - but never the less I am pretty
sure it works, and would certainly recommend it over the above code which
I think I do understand pretty well.
 
S

Sam Holden

Tintin ([email protected]) wrote:

: : > i' ve found this code for parsing form input
: > foreach (split(/[&;]/, $buffer)) {
: > s/\+/ /g ;
: > ($name, $value)= split('=', $_, 2) ;
: > $name=~ s/%([0-9A-Fa-f]{2})/chr(hex($1))/ge ;
: > $value=~ s/%([0-9A-Fa-f]{2})/chr(hex($1))/ge ;
: > ..........
: > i know it works

: Do you really? How do you know it works if you don't fully understand the
: code?

I know my car works, but I don't fully understand it.

Only because your car was designed and built by people you trust did
it correctly, complying with relevant safety and operating standards.
And it hasn't failed any of the tests you have tried with it.

Would you trust a car I built out of cardboard and rubberbands?
What if it drove around the block once without any problems?
I know my java compiler works but I understand that much less.

Only because you trust the author of the compiler understood how
it works and that it hasn't failed to produce correct output yet.
I haven't looked at the internal details of CGI.PM in ages, I don't
remember most of its documentation, I forget the _exact_ significance of
the qw:)standard) that I prefer over the object interface, I have never
bothered to figured out certain features that I haven't found the need to
use based on a high level description - but never the less I am pretty
sure it works, and would certainly recommend it over the above code which
I think I do understand pretty well.

Only because it has been widely tested and found to work.

Whereas code which has been "found" shouldn't be so trusted, and hence
without understanding the code you can't declare that "i know it works".
If other people who do understand how it works have declared
that "it works" then you could make such a declaration, if you trust
their judgement and knowledge.

If the code was written by someone you trust it's a different story,
but if it is code randomly found on the internet that usually isn't
the case.
 
G

Gunnar Hjalmarsson

Sam said:
Malcolm said:
Tintin said:
bbxrider wrote:

$name=~ s/%([0-9A-Fa-f]{2})/chr(hex($1))/ge ;
$value=~ s/%([0-9A-Fa-f]{2})/chr(hex($1))/ge ;

i know it works but the data is ascii characters to begin
with and don't understand what is the need for the
substitution
...
don't understand significance of the % sign,
not really sure what the {2} grouping is doing

Do you really [know that it works]? How do you know it works
if you don't fully understand the code?

I know my car works, but I don't fully understand it.

Only because your car was designed and built by people you trust
did it correctly, complying with relevant safety and operating
standards. And it hasn't failed any of the tests you have tried
with it.

Would you trust a car I built out of cardboard and rubberbands?
What if it drove around the block once without any problems?
I know my java compiler works but I understand that much less.

Only because you trust the author of the compiler understood how it
works and that it hasn't failed to produce correct output yet.
I haven't looked at the internal details of CGI.PM in ages, I
don't remember most of its documentation, I forget the _exact_
significance of the qw:)standard) that I prefer over the object
interface, I have never bothered to figured out certain features
that I haven't found the need to use based on a high level
description - but never the less I am pretty sure it works, and
would certainly recommend it over the above code which I think I
do understand pretty well.

Only because it has been widely tested and found to work.

Whereas code which has been "found" shouldn't be so trusted, and
hence without understanding the code you can't declare that "i know
it works". If other people who do understand how it works have
declared that "it works" then you could make such a declaration, if
you trust their judgement and knowledge.

If the code was written by someone you trust it's a different
story, but if it is code randomly found on the internet that
usually isn't the case.

You chose to focus on that "i know it works" statement.

At the same time it's worth noticing that OP did not address the
question whether to use CGI.pm or not. He asked for help to understand
a particular aspect of CGI. He showed an interest in learning. Your
choosen way to respond discourages people who attempts to understand
CGI. That's bad.

Shouldn't you better encourage people who deal with CGI to learn about
its implications? You _can_ do that and _still_ advice them to use CGI.pm.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top