Skip to content

Commit 234f01b

Browse files
committed
Answered some commenty questions, added a unicode char
1 parent db65979 commit 234f01b

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

categories/cookbook/01strings/01-04converting-values.pl

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,20 @@
66
77
=AUTHOR Scott Penrose
88
9-
You want to convert characters to their numeric value or vice-versa
9+
You want to convert characters to their codepoint number value or vice-versa
1010
1111
=end pod
1212

13-
# XXX I'm not sure "numeric value" is still correct for utf-8, as the actual
14-
# value(s) in memory can be very different. Maybe use "codepoint", or "codepoint
15-
# number"?
16-
1713
my $char = 'a';
1814
my $num = $char.ord;
1915
say $num;
2016
my $char2 = $num.chr;
2117
say $char2;
18+
my $copyright = '©';
19+
say $copyright ~ " : " ~ $copyright.ord ~ " : " ~ $copyright.ord.chr;
2220

2321
$char = 'foo';
24-
say $char.ord; # XXX is this correct behavior?
22+
# ord returns the codepoint of the first char in a string
23+
say $char ~ " : " ~ $char.ord;
2524

2625
# vim: expandtab shiftwidth=4 ft=perl6

0 commit comments

Comments
 (0)