Home > Blockchain >  How to read currency symbol in a perl script
How to read currency symbol in a perl script

Time:10-25

I have a Perl script where we are reading data from a .csv file which is having some different currency symbol . When we are reading that file and write the content I can see it is printing

Get <A3>50 or <80>50 daily

Actual value is

Get £50 or €50 daily 

With Dollar sign it is working fine if there is any other currency code it is not working

I tried

open my $in,  '<:encoding(UTF-8)',  'input-file-name'  or die $!;
open my $out, '>:encoding(latin1)', 'output-file-name' or die $!;

while ( <$in> ) {
   print $out $_;
}
$ od -t x1 input-file-name
0000000 47 65 74 20 c2 a3 35 30 20 6f 72 20 e2 82 ac 35
0000020 30 20 64 61 69 6c 79 0a
0000030 

od -t x1 output-file-name 0000000 47 65 74 20 a3 35 30 20 6f 72 20 5c 78 7b 32 30 0000020 61 63 7d 35 30 20 64 61 69 6c 79 0a 0000034

but that is also not helping .Output I am getting

Get \xA350 or \x8050 daily 
 od -t x1 output-file-name
0000000 47 65 74 20 a3 35 30 20 6f 72 20 5c 78 7b 32 30
0000020 61 63 7d 35 30 20 64 61 69 6c 79 0a
0000034

CodePudding user response:

Unicode Code Point Glyph UTF-8 Input File ISO-8859-1 Output File
U 00A3 POUND SIGN £ C2 A3 C2 A3 A3 A3
U 20AC EURO SIGN E2 82 AC E2 82 AC N/A 5C 78 7B 32 30 61 63 7D

("LATIN1" is an alias for "ISO-8859-1".)

There are no problems with the input file.

  • £ is correctly encoded in your input file.
  • is correctly encoded in your input file.

As for the output file,

  • £ is correctly encoded in your output file.
  • isn't found in the latin1 charset, so \x{20ac} is used instead.

Your program is working as expected.

You say you see <A3> instead of £. That's probably because the program you are using is expecting a file encoded using UTF-8, but you provided a file encoded using ISO-8859-1.

You also say you see <80> instead of . But there's no way you'd see that for the file you provided.

  •  Tags:  
  • perl
  • Related