perl-unicode

MD5 digest of UTF-8 string in Perl 5.8

2002-10-23 07:30:05
How can I calculate the MD5 message digest of a Unicode string in Perl
5.8? The MD5 hash algorithm naturally expects a sequence of bytes as its
input, and I have a string with a sequence of characters. I tried

  $ perl -e 'use Digest::MD5 qw(md5_hex); print md5_hex("\x{20ac}");'
  Wide character in subroutine entry at -e line 1.

but it seems that I have to explicitely convert my character string to a
byte sequence first.

How can I do this most efficently (keeping in mind, that it ought to be
a NOP internally as the string is already stored in UTF-8)?

Markus

-- 
Markus G. Kuhn, Computer Laboratory, University of Cambridge, UK
Email: mkuhn at acm.org,  WWW: <http://www.cl.cam.ac.uk/~mgk25/>

<Prev in Thread] Current Thread [Next in Thread>