spaze
09-13-2002, 05:09 AM
Hello!
Just wanted to know, that when I get values of input texts from a form, is there a way to change the data to correspond the true value without a huge amount of replacing? Here are the examples:
I'm getting the data from the form. If the data contains special characters like !"#¤%&/()= they are transferred by Perl into Hexcodes \n would be %0D%0A
Now I have to do the following lines for each data I receive from the form to replace the hexcodes with real value:
$data =~ s/%0D%0A/\n/g;
$data =~ s/%7C/|/g;
$data =~ s/%252C/,/g;
$data =~ s/%2C/,/g;
$data =~ s/%2F/\//g;
$data =~ s/%3A/:/g;
$data =~ s/%3B/;/g;
$data =~ s/%253B/,/g;
$data =~ s/%21/!/g;
$data =~ s/%27/'/g;
$data =~ s/%3F/?/g;
$data =~ s/%2B/-/g;
$data =~ s/%28/(/g;
$data =~ s/%29/)/g;
$data =~ s/%E5/å/g;
$data =~ s/%E4/ä/g;
$data =~ s/%F6/ö/g;
$data =~ s/%C5/Å/g;
$data =~ s/%C4/Ä/g;
$data =~ s/%D6/Ö/g;
$data =~ s/%22/"/g;
$data =~ s/%23/#/g;
$data =~ s/%A4/¤/g;
$data =~ s/%25/%/g;
$data =~ s/%26/&/g;
$data =~ s/%3D/=/g;
$data =~ s/%60/`/g;
You can imagine if I get 30 entries from the form, the script gets way too long and it is frustrating to copy/paste/edit.
So my question is, is there a way in Perl to get the TRUE data without this replacing hassle?
This is how I get the formdata:
read(STDIN, $buffer,$ENV{'CONTENT_LENGTH'});
$buffer =~ tr/+/ /;
$buffer =~ s/\r/ /g;
$buffer =~ s/\n/ /g;
@pairs = split(/&/,$buffer);
foreach $pair(@pairs){
($key,$value)=split(/=/,$pair);
$formdata{$key}.="$value";
}
$data=$formdata{'username'};
Just wanted to know, that when I get values of input texts from a form, is there a way to change the data to correspond the true value without a huge amount of replacing? Here are the examples:
I'm getting the data from the form. If the data contains special characters like !"#¤%&/()= they are transferred by Perl into Hexcodes \n would be %0D%0A
Now I have to do the following lines for each data I receive from the form to replace the hexcodes with real value:
$data =~ s/%0D%0A/\n/g;
$data =~ s/%7C/|/g;
$data =~ s/%252C/,/g;
$data =~ s/%2C/,/g;
$data =~ s/%2F/\//g;
$data =~ s/%3A/:/g;
$data =~ s/%3B/;/g;
$data =~ s/%253B/,/g;
$data =~ s/%21/!/g;
$data =~ s/%27/'/g;
$data =~ s/%3F/?/g;
$data =~ s/%2B/-/g;
$data =~ s/%28/(/g;
$data =~ s/%29/)/g;
$data =~ s/%E5/å/g;
$data =~ s/%E4/ä/g;
$data =~ s/%F6/ö/g;
$data =~ s/%C5/Å/g;
$data =~ s/%C4/Ä/g;
$data =~ s/%D6/Ö/g;
$data =~ s/%22/"/g;
$data =~ s/%23/#/g;
$data =~ s/%A4/¤/g;
$data =~ s/%25/%/g;
$data =~ s/%26/&/g;
$data =~ s/%3D/=/g;
$data =~ s/%60/`/g;
You can imagine if I get 30 entries from the form, the script gets way too long and it is frustrating to copy/paste/edit.
So my question is, is there a way in Perl to get the TRUE data without this replacing hassle?
This is how I get the formdata:
read(STDIN, $buffer,$ENV{'CONTENT_LENGTH'});
$buffer =~ tr/+/ /;
$buffer =~ s/\r/ /g;
$buffer =~ s/\n/ /g;
@pairs = split(/&/,$buffer);
foreach $pair(@pairs){
($key,$value)=split(/=/,$pair);
$formdata{$key}.="$value";
}
$data=$formdata{'username'};