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):
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; }
I understand what each line does ... for example ...
$value =~ tr/+/ /;
performs transliteration on $value and thus translates characters like !, @, #, etc. to their hex equivalents ... that is, # becomes %23.
$value =~ s/%(..)/pack("c", hex($1))/ge;
The line above then takes the two "hex" digits that make up the string and packs them into their hex equivalent.
$value =~ s/\t/ /g;
This code removes tabs?
$value =~ s/\0//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!

In reply to Need help understanding some code ... by Perobl

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.