Skip to content

Commit d3128c5

Browse files
committed
rupee
1 parent b0cc070 commit d3128c5

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
=title How to create an Indian Rupee symbol with Perl code
2+
=timestamp 2013-03-16T10:30:02
3+
=indexes binmode, Unicode, UTF8
4+
=status show
5+
=books beginner_book
6+
=author szabgab
7+
=index 1
8+
=archive 1
9+
=feed 1
10+
=comments 1
11+
=social 1
12+
13+
=abstract start
14+
15+
Recently I got an e-mail from one of the readers asking how to create a Indian Rupee symbol with Perl.
16+
I told him to check <b>what is the Unicode character for the Rupee symbol</b> and then to check
17+
<b>how to print Unicode characters with Perl</b>.
18+
19+
As this might be interesting to more people, let me show it here.
20+
21+
=abstract end
22+
23+
The first search led me to the Wikipedia page describing the <a
24+
href="http://en.wikipedia.org/wiki/Indian_rupee_sign">Indian Rupee sign</a>.
25+
26+
Apparently there is a <b>Generic Rupee sign</b> U+20A8 <hl>&#8360;</hl> and a specific <b>Indian Rupee sign</b> U+20B9
27+
<hl>&#8377;</hl>.
28+
29+
If you'd like to print a Unicode character to the screen (standard output or STDOUT), then you need to
30+
tell Perl to change the encoding of the STDOUT channel to UTF8. You can do this with the <hl>binmode</hl>
31+
function. (Check out the <a href="http://perldoc.perl.org/perluniintro.html">Unicode intro</a> for further details.)
32+
33+
For the specific code points you'd use the <hl>\x</hl> sign and then put the Hexadecimal values, in our case
34+
20A8 and 20B9 respectively in curly braces.
35+
36+
<code lang="perl">
37+
use strict;
38+
use warnings;
39+
use 5.010;
40+
41+
binmode(STDOUT, ":utf8");
42+
43+
say "\x{20A8}"; # &#8360;
44+
say "\x{20B9}"; # &#8377;
45+
</code>
46+
47+
48+
Of course if you are creating an HTML page then you'd better iclude the HTML entity representing the same character
49+
whith is an at sign (&) followed by a pound sign (#), followed by the decimal representation of the code point,
50+
followed by a semi-colon. To convert the Hexadecimal values to decmal values you can do the following in perl:
51+
52+
<code lang="perl">
53+
print 0x20A8, "\n"; # 8360
54+
print 0x20B9, "\n"; # 8377
55+
</code>
56+
57+
So in HTML you would include <hl>&amp;#8360;</hl> and <hl>&amp;#8377;</hl> respectively.
58+
59+
I have used perl 5.14.2 on Linux to test the above. In older versions of Perl the above might not work.
60+

0 commit comments

Comments
 (0)