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

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

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

 



kfmn
New User

Jul 22, 2014, 6:06 AM

Post #1 of 1 (17778 views)
Working with UTF-8 strings in -X operations and command line utilities Can't Post

Hello!

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:

Code
open(my $fh, "<:encoding(UTF-8)", "my.txt") or die $!; 
my $line=<$fh>;
chomp($line);
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!

Max


(This post was edited by kfmn 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