fork download
  1. #!/usr/bin/perl
  2.  
  3. # Idiom #287 Number of bytes of a string
  4.  
  5. use v5.10;
  6. use charnames qw( :full );
  7. use Encode;
  8.  
  9. binmode STDOUT, ':utf8';
  10.  
  11. my $text = "\N{LATIN SMALL LETTER E WITH ACUTE}";
  12. say length $text; # 1
  13.  
  14. my $utf8 = Encode::encode('UTF-8', $text);
  15. say length $utf8; # 2
  16.  
Success #stdin #stdout 0.05s 10344KB
stdin
Standard input is empty
stdout
1
2