I solved the question, thank you all very much! The solution was

# i added use Encoding qw(encode decode); # and in sub foo i decoded the things from File::Find. eg sub foo { $file_name = decode("UTF-8", $_); } # cheers!

here is the question and old code

# basically i want to go through a directory with File::Find # and print the (non-asciian) filenames to a file. # let's go through it incrementally, basic assumptions use utf; use File::Find; open (OUT, '>:encoding(UTF-8)', '/tmp/tmp.sql'); open (IN, '<:encoding(ISO-8859-15)',$file_name); sub foo { print "$_\n"; print OUT "$_\n"; # the IN file is used, but none of it's contents are # written to the out file, only the filename $_ is # needed in the OUT file } # when i now execute find(\&foo, $mydir); # it will print fine to the terminal (i use GNU/Debian) # but mojibake to the file # if i prepend this binmode( STDOUT, ':encoding(UTF-8)' ) or die $!; binmode( STDIN, ':encoding(UTF-8)' ) or die $!; # to the script # then it prints mojibake both to terminal and to file # it would be more logical if the other way around

what is it that i miss to encode/decode?

I haven't had problems with utf files before, but this is the first time i use File::Find for interaction with the file system


In reply to File::Find and UTF-8 problems by lagle

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.