I have a textfile encoded in UTF-16. Each line contains a number of columns separated by tabs. For those who care, the file is a playlist TXT export from iTunes. Column #27 contains a filename.
I am reading it using Perl 5.8.8 in Linux using code similar to:
binmode STDIN, ":encoding(UTF-16)";
while(<>)
{
chomp;
my @cols = split /\t/, $_;
my $filename = $cols[26]; # Column #27 contains the filename
print "File exists!" if (-e "$filename");
}
(Please note: I've shortened this code snippet. In my actual code I do some substitutions to convert the absolute windows filename used by iTunes into a filename valid on my Linux box)
Even though the files exist, the (-e) file test does not return true. I believe it has something to do with the string being in UTF-16 but cannot figure out what the problem is. The actual filename uses only ASCII characters. And the filename prints correctly if I print the $filename variable.
Can filenames in Perl be in UTF16? Any ideas how to get this code snippet to work?