Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi,

I've a text file where content is in danish language. Now, if I try to read that file and print the contents only then they're modified. How can I get contents in exactly the same danish language. Please note that I've to find some patterns from this text file, that's why I'm trying to print here the file as it is.

$file = '/test.txt'; open(INFO, $file); @lines = <INFO>; close(INFO); print @lines;

Replies are listed 'Best First'.
Re: how to get exactly same text from a file
by McA (Priest) on Nov 26, 2012 at 12:22 UTC

    Hi,

    this is very intersting. What is the language of the output? Which Perl version do you use?

    Best regards
    McA

Re: how to get exactly same text from a file
by Anonymous Monk on Nov 26, 2012 at 13:18 UTC
      Thanks but it didn't solve my proble. Can you specify , how to convert the garbled character mentioned above into it's respective character.
        Which encoding is used for the text in your source file? Which encoding would you like to use for output? If you just output the content of your inputfile (using cat, or, if you run Windows, using TYPE), does it look right?

        -- 
        Ronald Fischer <ynnor@mm.st>

        Thanks but it didn't solve my proble. Can you specify , how to convert the garbled character mentioned above into it's respective character.

        It wasn't meant to solve your problem, it is meant to teach you how stuff works, and what you need to do to solve your problem

        "garbled characater" is a something you should avoid when trying to get help, you should talk about bytes, or better yet, perl code

        perl -MData::Dump -MFile::Slurp -e " dd scalar read_file shift, { qw/ binmode :raw / }; " AnyKindOfInputFile > ThatFilesBytesAsPerlCode.pl

Re: how to get exactly same text from a file
by karlgoethebier (Abbot) on Nov 26, 2012 at 16:24 UTC

    I tried to reproduce this using your code.

    «The Crux of the Biscuit is the Apostrophe»

Re: how to get exactly same text from a file
by Anonymous Monk on Nov 26, 2012 at 13:15 UTC
    Ok, my perl is 5.14. this is the garbled character I'm getting from the website and I want to convert it into it's real form. Any idea how to do this?
      Ok, my perl is 5.14. this is the garbled character : ต้มยำกุ้ง I'm getting from the website and I want to convert it into it's real form. Any idea how to do this?

        Since you're using HTTP (you should've said so in the beginning!), which encoding do you serve your output with? (the Content-Type header.) Which encoding is the file saved with? (ISO8859-1, 8859-15, UTF-8, UTF-16LE?) What output does perl -MData::Dumper -e '$Data::Dumper::Useqq=1;  print Dumper(scalar <>)' test.txt give you? Can you view the file in a terminal? What is your terminal's encoding?

        (I'm interested in a Danish-to-Hindi translator, so if your code happens to output the file in Hindi, I'd love to examine it.)