I also see some rather strange things in this code. Even the first line:  read (STDIN, $temp, ENV{'CONTENT_LENGTH'}); looks strange to me! A more normal thing would be:  my $actually_read = read (FILEHANDE, $temp, $max_buf_size);

If $actually_read == $max_buf_size that could mean that there is more left to be read. Also anything that doesn't have actual data in, is "unknown" (not necessarily what Perl calls undef) because there could be some previous value in $temp? So if you are going to process input data like this, attention needs to be paid to what is actually in the $buffer (number of bytes), not the max size that you intend to allow for this read.

I also don't see anything that would lead me to believe that you are reading anything but ASCII or unicode representable text in which case more common Perl string reads would be more appropriate. If these strings end in NUL, you can define $/=0; (input record separator instead of default of \n). Also, like others, I don't see how this code works for any more than one pair.

If you could put a short line into a test file, text.txt and then run this small script, we would see what is really in there:

#!/usr/bin/perl -w use strict; my $buf; open (IN, "test.txt") || die "can't open test.txt"; binmode (IN); my $actual = read (IN, $buf, 2048); foreach my $i (0..$actual-1) { printf "%02X ", ord(substr($buf,$i,1)); }

In reply to Re: Need help understanding some code ... by Marshall
in thread 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.