CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Win32 Programming Help: Working with UTF-8 strings in -X operations and command line utilities: Edit Log

New User

Jul 22, 2014, 6:06 AM

Views: 29150
Working with UTF-8 strings in -X operations and command line utilities


I have an UTF-8 text file my.txt (without BOM) which contains a single line with a path to an existing folder, composed of latin, cyrillic and greek letters, for example
c:/my folder/Новая папка Ωγσ

I'd like to have a script which can read this file and answer if this folder exists indeed or no.

My first attempt was as follows:

open(my $fh, "<:encoding(UTF-8)", "my.txt") or die $!; 
my $line=<$fh>;
if (-d $line){ print "Success!"; }
else{ print "Failure"; }

and a failed to get "Success!" message.

If the path consists of only latin and cyrillic symbols then its converting to CP1251 with Encode::encode helps (my Windows is cyrillic). But with both cyrillic and greek letters it fails too.

By the way, if the file contains BOM it is read into the line as a strange start symbol. How can i prevent this?

Help me, please!


(This post was edited by kfmn on Jul 22, 2014, 7:36 AM)

Edit Log:
Post edited by kfmn (New User) on Jul 22, 2014, 7:36 AM

Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives