When you have a problem such as two strings DATE
and ABC
being concatenated, and the end result is ABCE
, or one of the strings overwriting the other, a likely scenario is that you have a file from another OS, with the line endings \r\n
, which are chomp
ed, resulting in the string DATE\rABC
when concatenated, which then becomes ABCE
when printed.
In other words:
my $foo = "DATE\r\n";
my $bar = "ABC\r\n"; # \r\n line endings from file
chomp($foo, $bar); # removes \n but leaves \r
print $foo . $bar; # prints ABCE
To confirm, use
use Data::Dumper;
$Data::Dumper::Useqq = 1;
print Dumper $DATATABLE[$i][$k]; # prints $VAR1 = "DATE\rABC\r";
To resolve, instead of chomp
use a regex such as:
$foo =~ s/[\r\n]+\z//;