Foreign characters in filenames, revisited

Discussion in 'Perl Misc' started by P, Feb 4, 2005.

  1. P

    P Guest


    Thanks to your help I have learned how to open files which have
    filenames containing foreign characters (like umlauts). I now have
    a different, although slightly related problem. I am reading text
    from a file. This file is a list of other files, each of which I have
    to open for reading. I do something like this:

    while (<>) {
    # $_ contains one filename

    open ( IN, $_ ) or die $!;

    # do stuff with the opened file

    This is fine as long as the filename to be opened doesn't contain
    foreign characters. It doesn't open such files. For example, if $_

    "Todo El Ano.log"

    then the open() will fail even though the file clearly exists. It has
    no problems whatsoever with any filenames containing "normal"

    Is there any way to properly open these kinds of files when getting
    their names from a text file?
    P, Feb 4, 2005
    1. Advertisements

  2. P

    Shawn Corey Guest

    Your problem is not with the filename but in the way it is read. You
    have to change the way STDIN is read. Since I don't know what system
    you're using I can tell exactly what is needed but if the filenames were
    in UTF-8, then before the 'while(<>)...' use:

    while(<>) {

    --- Shawn
    Shawn Corey, Feb 4, 2005
    1. Advertisements

  3. P

    Wes Groleau Guest

    Assuming that "foreign characters" means characters not
    often found in English, the above has none. So I further
    assume it was “Todo El Año.logâ€

    (All Year vs. Entire Anus)

    Wes Groleau

    After the christening of his baby brother in church, Jason sobbed
    all the way home in the back seat of the car. His father asked him
    three times what was wrong. Finally, the boy replied, "That preacher
    said he wanted us brought up in a Christian home, and I wanted to
    stay with you guys."
    Wes Groleau, Feb 5, 2005
  4. P

    Joe Smith Guest

    Does it make any difference when using the three-argument open()?

    open (IN, '<', $_) or die "Cannot open '$_' for input: $!\n";

    Joe Smith, Feb 7, 2005
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.