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 = <> ) |