in reply to Re: How to write a utf-8 file
in thread How to write a utf-8 file

Thanks for your response

Really I am not able to understand what how you are trying to help me

As I am clearly mentioned in my mail, I have no problem in reading the xml

problem is only with writing into a xml

I want to confirm, which is the correct way, how can I write other than english text properly in the OUT xml?

Thanks

srikrishnan

Replies are listed 'Best First'.
Re^3: How to write a utf-8 file
by elef (Friar) on Apr 13, 2011 at 09:43 UTC
    As ikegami posted above, your code is correct.
    Try it with a different input file and open the output file with a different text editor.
    Occasionally, Notepad++ fails to show unicode charters for me even when the file itself is OK. Close and reopen usually fixes it.
Re^3: How to write a utf-8 file
by SuicideJunkie (Vicar) on Apr 13, 2011 at 15:12 UTC

    Consider what happens if the file doesn't exist:

    In your original code, things will go wrong with no explanation.
    In the suggested alternative, the code will print "can't open UTF-8 encoded filename: File Not Found" and then exit safely.

    Depending on the specific problem, $! could be file not found, permission denied, out of disk space, locked by another process, etc... whatever reason the OS gives. Extremely helpful!

    You're already using the 3-arg version of open, which is good. You can add lexical file handles ($inFH rather than just IN), checking the return value (the "||", or better yet, "or"), and printing $! when things do go wrong. These are all good habits to get into, as they will help you avoid debugging pain in the future.