You can check the Site How To section to learn how to post code correctly (putting "<code>" and "</code>" around it).

You are using the wrong sort of test in the snippet of code that you provided. Given that "$descr" stores a string of some length, and you want to test whether or not it's longer than 2000 characters, you need to do it this way:

if ( length( $descr ) <= 2000 ) { $descr =~ tr/",//d; # remove double-quotes and commas print $descr; } else { print "Description is too long (over 2000 characters)\n"; }
Of course, that has nothing to do with the symptom of the shrinking string value. You haven't posted the part of the code relevant to that problem, but my guess is you might have a loop that looks something like this:
$descr = <>; while (<>) { chop $descr; print $descr; }
The problem here is that while (<>) reads a line of input into $_, not into $descr; but then inside the loop, you are truncating and printing $descr, which ends up being the same string, getting shorter at each iteration until chop has nothing left to work on and/or the while loop reaches the end of the input file. You should either use $_ throughout (instead of $descr) or else you should use:   while ( $descr = <> )

In reply to Re: Can I read a text of characters and numbers as one string? by graff
in thread Can I read a text of characters and numbers as one string? 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.