3

I am am using Perl open for opening new file on Solaris 10 as follows:

open($fh, ">$filePath");

What is default file character encoding on my system with this call?

The output from locale command is given below

LANG=
LC_CTYPE="C"
LC_NUMERIC="C"
LC_TIME="C"
LC_COLLATE="C"
LC_MONETARY="C"
LC_MESSAGES="C"
LC_ALL=
0

1 Answer 1

3

This was not as easy a question to answer as I thought it would be.

The default encoding is raw, which is suitable for binary data. Any character with an ordinal value under 256 is passed as is:

$ perl -e 'print chr(0xFF)' | od -c
00000000 377
00000001

The curious thing is what happens when you try to write a character above ordinal value 255. Then it looks like you get UTF-8 encoding.

$ perl -e 'print chr(0x100)' | od -c
00000000 304 200
00000002

I don't know where or if this behavior is documented.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for quick reply, this means the once file is opened based on whether character is under 255 it will be written as raw or UF8 if above 255 on the same file handle ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.