Returns the numeric value of the first character of EXPR. If EXPR is an empty string, returns 0. If EXPR is omitted, uses $_.

When utf8 is properly set

examples/ord_utf8.pl

  1. use strict;
  2. use warnings;
  3. use 5.010;
  4. use utf8;
  5.  
  6. say ord('a'); # 97
  7. say ord('b'); # 98
  8. say ord('A'); # 65
  9. say ord('='); # 61
  10. say ord('abc'); # 97
  11.  
  12. say ord('ű'); # 369 (Hungarian)
  13. say ord('ñ'); # 241 (Spanish)
  14.  
  15. say ord('א'); # 1488 (Hebrew Aleph)
  16. say ord('אב'); # 1488 (Hebrew Aleph and Bet)
  17. say ord('ב'); # 1489 (Hebrew Bet)
  18.  
  19. say ord('٣'); # 1635 (Arabic 3)
  20.  
  21.  

When utf8 is not set

examples/ord.pl

  1. use strict;
  2. use warnings;
  3. use 5.010;
  4.  
  5. say ord('a'); # 97
  6. say ord('b'); # 98
  7. say ord('A'); # 65
  8. say ord('='); # 61
  9. say ord('abc'); # 97
  10.  
  11. say ord('ű'); # 197 (Hungarian)
  12. say ord('ñ'); # 195 (Spanish)
  13.  
  14. say ord('א'); # 215 (Hebrew Aleph)
  15. say ord('אב'); # 215 (Hebrew Aleph and Bet)
  16. say ord('ב'); # 215 (Hebrew Bet)
  17.  
  18. say ord('٣'); # 217 (Arabic 3)

See also the chr function as the opposite of ord.