Perobl has asked for the wisdom of the Perl Monks concerning the following question:
I have been asked to update a script that I did not write. The script is for form processing and the section I'm sharing is basically used to evaluate user data submitted as key-value pairs.
I'm having trouble seeing any tangible purpose in four lines of code below (where $value is evaluated):
I understand what each line does ... for example ...read (STDIN, $temp, $ENV{'CONTENT_LENGTH'}); @pairs = split(/&/, $temp); foreach $item(@pairs) { ($key, $value) = split(/=/, $item, 2); $value =~ tr/+/ /; $value =~ s/%(..)/pack("c", hex($1))/ge; $value =~ s/\t/ /g; $value =~ s/\0//g; }
performs transliteration on $value and thus translates characters like !, @, #, etc. to their hex equivalents ... that is, # becomes %23.$value =~ tr/+/ /;
The line above then takes the two "hex" digits that make up the string and packs them into their hex equivalent.$value =~ s/%(..)/pack("c", hex($1))/ge;
This code removes tabs?$value =~ s/\t/ /g;
And this code removes nulls? I'm missing the point of these four lines of code used together. It doesn't seem like they're really protecting anything??? Am I missing something? Thanks for your help!$value =~ s/\0//g;
Back to
Seekers of Perl Wisdom