develooper Front page | perl.perl5.porters | Postings from August 2013

Re: [perl #119239] started out as doc clarification needed in 'eval...but...

Thread Previous
From:
Lukas Mai
Date:
August 17, 2013 07:17
Subject:
Re: [perl #119239] started out as doc clarification needed in 'eval...but...
Message ID:
520F235E.7010302@gmail.com
On 16.08.2013 16:53, Ricardo Signes wrote:
>
> Consider this program:
>
>    use 5.18.0;
>    {
>      my $str = "“犬夜叉”";
>      my @codepoints = split '', $str;
>      say join q{ }, map {; sprintf 'U+%04X', ord } @codepoints;

This could be replaced by

     say sprintf "%*v04X", " ", $str;

(well, almost: the U+ bits are missing).

If you're debugging a problem and you just want to see what Perl thinks 
your codepoints are,

     printf "%vd\n", $str;  # or printf "%vx\n", $str

can be extremely useful.

>      say $str;
>      say $str =~ /\p{InCJK}/ ? "InCJK" : "Not InCJK";
>    }
>
>    say '-' x 78;
>
>    {
>      use utf8;
>      my $str = "“犬夜叉”";
>      my @codepoints = split '', $str;
>      say join q{ }, map {; sprintf 'U+%04X', ord } @codepoints;
>      say $str;
>      say $str =~ /\p{InCJK}/ ? "InCJK" : "Not InCJK";
>    }
>


-- 
Lukas Mai <plokinom@gmail.com>

Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About