I am stymied by a result I am getting from my perl script. Here are the results:
Line = 'org_name,"My Organization"' Field = 'org_name ' Field Length = 9 Trim Length = 'org_name ' Line ($line) is a string to which I want to compare some key words. Field ($field) is one of the key words. I have placed single quotes ar +ound the value so I can see its length. Field Length ($length) is the result of the Perl length($field) functi +on. Trim Length ($trim_length) is the result of substr ($field, 0, $length +). $field is read from a database table using the @fields = qx{query}; The relationship between @fields and $field comes from a foreach @fiel +d (@fields) loop.
If I write the results of the qx{query} to a file and inspect the contents with vi, each line is the appropriate length (ie, length($field)). Why are $field and trim_length so long? The extra bytes are keeping my compare to $line from finding equality. What can I do to trim the extra bytes from the $field values? Obviously the substr isn't working. Any help greatly appreciated.

In reply to Extraneous Data in Variable 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.