Dear Monks:

In a program that parses a text file by opening and splitting a simple two-column file into array elements, I find that about 50% of the 3700 or so entries print out with the first element visually truncated. I don't mean that the value has changed, just that anything I try to print out in that first position is missing the first 2 characters on about half of the lines as they are displayed. If I 'pad' the line with 2 spaces on the print line, visibility is restored. I can print out the values separately in the program without difficulty. This seems to affect any array values or other variables (or literals) I try to print.

This has me stumped. I've searched Google on strings like "perl print not visible" or "perl print truncates" to no avail. Keep in mind that about half of the entries print with no drama at all. I have scrubbed the source data for unprintable characters, etc. Anything--and I mean anything (even the word RECORD) is truncated on the output of the program for those certain records.

Here's a sample of the code with some redactions:

while (defined(my $line = <FH>)) { chomp $line; my @hostpair = split(' ',$line); my $host = $hostpair[0]; my @FQDN = split(/ /,`host $host`,2); my $OWNER; if (exists $MYDB{uc($host)}) { $OWNER = $MYDB{uc($host)} } else { $OWNER = "OTHER"; } print "$host \t $FQDN[0]\t $hostpair[1] \t $OWNER \n"; }

The source data is a simple two-column space-delimited file showing short hostname in column 1 and a three-letter identifier in column 2

Your help is much appreciated!


In reply to Leading Characters Not Visible for Certain Array Elements While Printing by justsomeguy

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.