The problem is that you have Windows line endings in this file, which is why when you use linux, your chomp
is not removing line endings properly. It does not explain why chop
does not remove the last character, which should be \r
after chomp
.
Your output
';AR6 = 'NC_005803
Indicates that the last character in the string is in fact \r
. This is not an actual problem with the string, just with the visual representation. If you want to see this character written out literally, you can use the option
$Data::Dumper::Useqq = 1;
Which will then produce the output
$VAR6 = "NC_005803\r";
How to fix it?
A simple fix is to use the dos2unix
utility in linux to fix the file. To fix it in Perl, you can do something like
s/[\r\n]*\z// for @nodes; # remove all \r and \n from end of string
s/\s*\z// for @nodes; # remove all whitespace from end of string
s/\r//g for @nodes; # remove all \r from string
tr/\r//d for @nodes; # same