good chemistry is complicated, and a little bit messy -LW |
|
PerlMonks |
Re: utf8 "\xB7" does not map to Unicode at /usr/local/bin/бибс/об‰ line 112.by graff (Chancellor) |
on Nov 03, 2015 at 11:14 UTC ( [id://1146803]=note: print w/replies, xml ) | Need Help?? |
You haven't given us enough information. Do you have files with non-ASCII files names (in /usr/local/bin/) ? If so, are you sure about what character encoding is being used for those file names?
I'm guessing you do have non-ASCII file names, they are utf8-encoded, and you probably don't have these lines near the top of the script: and/or maybe you don't have this: which would let you do something like this: That snippet, when used with the other lines above, will show you the file names found in your /usr/local/bin/. If you'd rather use the output of the "find" utility, it might go like this: Note that the first example (using opendir/readdir) prints just the names of files in that one directory, and the second example (with "find") prints the absolute path names for all files in that directory and in all its subdirectories. (Update: and notice that "\n" has to be added in the first, but is already included in the file name string in the second.) (Also, if all your file names are plain ASCII, the above scripts still work, because ASCII is a subset of utf8.) Now, if some of your file names have non-ASCII characters, and use some character encoding other than utf8 (e.g. koi8-r or iso-8859-5 or cp1251 or whatever), you have to figure what that encoding is, and use it in place of "utf8" when you call decode() or open( ..., "|-...", "find ..."). If some of your file names have been corrupted (e.g. they were utf8-encoded but somehow got "renamed" with a bad byte sequence), you'll need to fix that. (Update: I believe it is possible that a single directory can contain some file names that use one encoding, and other file names that use a different encoding. You might want to look closely at the man page for Encode, especially the part about catching errors ("FB_CROAK"), and you may also want to look at Encode::Guess.)
In Section
Seekers of Perl Wisdom
|
|