Perl Output Chinese is garbled

Source: Internet
Author: User

Test file when found that the output of Chinese is garbled, so learned a bit of Perl encode principle. Now do a summary:
The basic knowledge of Perl: In Perl, there are only two forms of strings. One is octets, a 8-bit sequence, which is the byte array we usually say. Another type of UTF8 encoded string, Perl tube it is called string. That is to say: Perl only knows two encodings: Ascii (octets) and UTF8 (string).

So when the output is garbled, the UTF8 encoding should be converted into a form acceptable to the user. For example, Chinese with gb2312.

My $s = ":< Chinese keywords >= British Royal Society;; The Journal of Philosophical Transactions Physical sciences;; Scientific communication. ";

$a = $s =~/>= (. +) $/;

Print encode (' gb2312 ', $ $). " \ n "; #输出英国皇家学会;; The Journal of Philosophical Transactions Physical sciences;; Scientific communication.

Perl Output Chinese is garbled

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.