Geronimo24
Programmer
Hi,
I have a very simple Perl script that I am using to read in values from tab-delimited text files, reformat those values and print them to an output file.
I simply read in each line of the file and save each value from that line to a variable by using the split function. The one problem that I sometimes coming across is that sometimes when my program reads in a line,
Example:
Perl Java C
The last value that it reads has this very strange character appended to it. Using chop and chomp don't get rid of it! When I print out the corrupted value to my output file, it is as if it contains a carriage return at the end of that value (I get a new line after the value every time I print it out to my output file).
I put in some debug statements and got some very strange results ($value is the corrupted variable):
line 1 $howLong = length($value);
line 2 print "$value\n";
line 3 print "length: $howLong\n";
line 4 print "$value hello\n";
line 5 print "done\n";
Assuming that $value contains "dinosaur@hotmail.com," the ouput is:
dinosaur@hotmail.com
length: 19 [length should be 18!]
[space]hellour@hotmail.com
done
The last line of the output is very puzzling!!!
When I modify the debug statements so that I take out the \n from lines 2 and 4...
line 1 $howLong = length($value);
line 2 print "$value";
line 3 print "length: $howLong\n";
line 4 print "value hello";
line 5 print "done\n";
I get this even weirder outputoutput (assume $value contains dinosaur@hotmail.com:
length 19hotmail.com
[space]hellodoneotmail.com
The only way that I have been able to get rid of this puzzling character that somehow corrupts my variable is by doing this:
$value = substr($value, 0, length($value) - 2))
Is there a cleaner, safer way that I can get rid of this mystery character? I don't want to indiscriminately always chop off the last character since I don't always have the problem. Someone told me it might be a ^M character, but doing a substitution in my script does not get rid of it!
Anyone have any idea how to fix this??
I have a very simple Perl script that I am using to read in values from tab-delimited text files, reformat those values and print them to an output file.
I simply read in each line of the file and save each value from that line to a variable by using the split function. The one problem that I sometimes coming across is that sometimes when my program reads in a line,
Example:
Perl Java C
The last value that it reads has this very strange character appended to it. Using chop and chomp don't get rid of it! When I print out the corrupted value to my output file, it is as if it contains a carriage return at the end of that value (I get a new line after the value every time I print it out to my output file).
I put in some debug statements and got some very strange results ($value is the corrupted variable):
line 1 $howLong = length($value);
line 2 print "$value\n";
line 3 print "length: $howLong\n";
line 4 print "$value hello\n";
line 5 print "done\n";
Assuming that $value contains "dinosaur@hotmail.com," the ouput is:
dinosaur@hotmail.com
length: 19 [length should be 18!]
[space]hellour@hotmail.com
done
The last line of the output is very puzzling!!!
When I modify the debug statements so that I take out the \n from lines 2 and 4...
line 1 $howLong = length($value);
line 2 print "$value";
line 3 print "length: $howLong\n";
line 4 print "value hello";
line 5 print "done\n";
I get this even weirder outputoutput (assume $value contains dinosaur@hotmail.com:
length 19hotmail.com
[space]hellodoneotmail.com
The only way that I have been able to get rid of this puzzling character that somehow corrupts my variable is by doing this:
$value = substr($value, 0, length($value) - 2))
Is there a cleaner, safer way that I can get rid of this mystery character? I don't want to indiscriminately always chop off the last character since I don't always have the problem. Someone told me it might be a ^M character, but doing a substitution in my script does not get rid of it!
Anyone have any idea how to fix this??