Don't chase your tail when you run into a problem like this. The weak link in our code is the assumptions we make. More often than not, after we have enough experience, we can rely on our assumptions because we've learned which ones are safe, which ones aren't, and which ones to question first when something goes wrong.

DATA is a special filehandle. I don't recall any documented warning against using it to open a regular file, but I don't think I'd assume that I could use it the way you're using it without running into a problem somewhere. When Perl has a special use for a word, I try not to use that word unless I want the Perl magic that comes with it.

This may seem simple and/or obvious, but you're making the assumption that your code is reading input, but I don't see any proof of that. I would suggest adding a print statement at the top of the while() loop so you can confirm the input:

print STDERR "bytes: ", length, "\n";

If the reported input length for each line is greater than zero, you can assume you have data to work with. If the print statement is never executed, you know that you're not reading input, I suspect this is the case. I would suggest that you use a different filehandle, test again, then look for misspellings, make sure your input file isn't zero length, etc.

Oh, and you are using warnings and strict, aren't you?


In reply to Re: string parsing by converter
in thread string parsing by Anonymous Monk

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.