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:binmode STDOUT, ":utf8"; binmode STDERR, ":utf8";
which would let you do something like this:use Encode;
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:opendir( my $dir, "/usr/local/bin" ) or die "Can't read /usr/local/bin +: $!\n"; while ( my $fname = decode( "utf8", readdir( $dir ))) { print $fname, "\n"; }
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.)#!/usr/bin/perl use strict; use warnings; use Encode; binmode STDOUT, ":utf8"; binmode STDERR, ":utf8"; open(my $find,"|-:utf8","find /usr/local/bin -type f") or die "Can't r +un find: $!\n"; while ( <$find> ) { print; }
(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 reply to Re: utf8 "\xB7" does not map to Unicode at /usr/local/bin/бибс/об‰ line 112.
by graff
in thread utf8 "\xB7" does not map to Unicode at /usr/local/bin/бибс/об‰ line 112.
by nikolay
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |