in reply to treat files with umlauts (utf)

G'day Mike,

Welcome to the monastery.

In what way does '-f' "not work any more"?

Please provide more information on "I cannot copy or move $scandir."/".$files[0]". How are attempting to copy and move? What's happening? What errors, warnings or other feedback are you getting?

Are you asking Perl to point out problems to you (e.g. strict, warnings, autodie, etc.)? The documentation shows opendir reporting problems in "$!": you're using "$@".

You're using package global variables exclusively (in the code you've shown): this could be causing any number of problems. Without seeing all of your code, it's impossible to tell. Use lexical variables and avoid the issue altogether.

I created this directory (some characters may not render in your browser but the filenames indicate the code points):

$ ls -al pm_1080490_utf8_readdir
total 0
drwxr-xr-x    5 ken  staff    170  1 Apr 21:01 .
drwxr-xr-x  599 ken  staff  20366  1 Apr 21:02 ..
-rw-r--r--    1 ken  staff      0  1 Apr 20:47 Fehler für Projekt x.txt
-rw-r--r--    1 ken  staff      0  1 Apr 20:58 ᚠᚡᚢᚣᚤᚥᚦ (U+16a0 to U+16a6)
-rw-r--r--    1 ken  staff      0  1 Apr 21:01 🜁 🜂 🜃 🜄 (U+01f701 to U+01f704)

I ran this script:

#!/usr/bin/env perl -l use strict; use warnings; use autodie; my $scandir = './pm_1080490_utf8_readdir'; opendir(my $dh, $scandir); my @files = grep { -f "$scandir/$_" } readdir $dh; print for @files;

And got this output:

Fehler für Projekt x.txt
ᚠᚡᚢᚣᚤᚥᚦ (U+16a0 to U+16a6)
🜁 🜂 🜃 🜄 (U+01f701 to U+01f704)

So, I'm unable to reproduce your problem.

Try running exactly the same code as I did (except with a different value for $scandir) and report the result. Show the full output of any errors, warnings, or other messages: vague references to "does not work" and the like are of no use at all. The guidelines in "How do I post a question effectively?" explain what information is useful and how to present it.

-- Ken

Replies are listed 'Best First'.
Re^2: treat files with umlauts (utf)
by hazylife (Monk) on Apr 01, 2014 at 11:08 UTC
    So, I'm unable to reproduce your problem.
    That's because your code is missing the two key ingredients:
    use utf8; ... my $scandir = 'something with umlauts it it';
      "That's because your code is missing the two key ingredients:"

      No, it's not.

      "use utf8;"

      Neither my code nor the code the OP posted requires the utf8 pragma. See the following, from that documention, which it shows in bold-faced type:

      "Do not use this pragma for anything else than telling Perl that your script is written in UTF-8."
      "my $scandir = 'something with umlauts it it';"

      The OP does not say that $scandir contains umlauts. The only mention of umlauts by the OP is:

      "Given is a file which contains german umlauts in its name (e.g. 'Fehler für Projekt x.xls')"

      He says "file" and provides what would be resonable to assume is an MS Excel spreadsheet file. There's nothing about any directory whose name contains umlauts.

      -- Ken

        The OP does not say that $scandir contains umlauts.
        Neither my code nor the code the OP posted requires the utf8 pragma.
        True, but the OP did mention "a SLES Linux with UTF-8 support switched on", and, strictly speaking, use utf8 is not the only means of getting $scandir flagged as UTF-8:
        binmode(STDIN, ':encoding(UTF-8)'); chomp(my $scandir = <STDIN>); #OR $ perl -CS -e 'chomp(my $scandir = <STDIN>); ...' #OR $ perl -CA -e 'my $scandir = shift; ...' <dir>