about utf8

Hello,

I'm not much sure what's the difference between the two statements below?

use encoding 'utf8';
use utf8;

I have read their documents but not very understandful.

Thanks.

--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
Practical Perl [ Sa, 29 Januar 2011 09:27 ] [ ID #2054065 ]

Re: about utf8

On 11-01-29 03:27 AM, xiaolan wrote:
> Hello,
>
> I'm not much sure what's the difference between the two statements below?
>
> use encoding 'utf8';
> use utf8;
>
> I have read their documents but not very understandful.
>
> Thanks.
>

`use utf8;` tells the compiler that the script is written in UTF-8.
That's all it does.

`use encoding 'utf8'` tells it the srcipt is in UTF-8, its literal
strings are in UTF-8, and STDIN, STDOUT, and DATA are in UTF-8.

$ perl -Mutf8 -e'print"\x{2022}\n";'
Wide character in print at -e line 1.

$ perl -Mencoding=utf8 -e'print"\x{2022}\n";'


The second one does not complain about a wide character since STDOUT has
been change to UTF-8.


--
Just my 0.00000002 million dollars worth,
Shawn

Confusion is the first step of understanding.

Programming is as much about organization and communication
as it is about coding.

The secret to great software: Fail early & often.

Eliminate software piracy: use only FLOSS.

--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
Shawn H Corey [ Sa, 29 Januar 2011 14:46 ] [ ID #2054066 ]

Re: about utf8

On Sat, Jan 29, 2011 at 9:46 PM, Shawn H Corey <shawnhcorey [at] gmail.com> wrot=
e:
> On 11-01-29 03:27 AM, xiaolan wrote:
>>
>> Hello,
>>
>> I'm not much sure what's the difference between the two statements below=
?
>>
>> use encoding 'utf8';
>> use utf8;
>>
>> I have read their documents but not very understandful.
>>
>> Thanks.
>>
>
> `use utf8;` tells the compiler that the script is written in UTF-8. That'=
s
> all it does.
>
> `use encoding 'utf8'` tells it the srcipt is in UTF-8, its literal string=
s
> are in UTF-8, and STDIN, STDOUT, and DATA are in UTF-8.
>
> $ perl -Mutf8 -e'print"\x{2022}\n";'
> Wide character in print at -e line 1.
> =E2=80=A2
> $ perl -Mencoding=3Dutf8 -e'print"\x{2022}\n";'
> =E2=80=A2
>
> The second one does not complain about a wide character since STDOUT has
> been change to UTF-8.
>

Thanks for this excellent answer.

Regards.

--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
Practical Perl [ So, 30 Januar 2011 05:47 ] [ ID #2054101 ]
Perl » gmane.comp.lang.perl.beginners » about utf8

Vorheriges Thema: parse arguments passed to subroutines
Nächstes Thema: help to capture the elements, every 8th, followed by 7 elements