Names to ids
Dirk Koopman
djk at tobit.co.uk
Wed Jan 25 14:31:06 GMT 2006
On Wed, 2006-01-25 at 13:40 +0000, Simon Wistow wrote:
> I need to turna filename into a numeric id in a repeatable manner (i.e
> the same filename must always produce the same number).
>
> My first thought (md5_hex the name and then hex the reuslt to get an
> integer) gets an overflow error unless I truncate to the first 8
> characters.
>
If you are prepared to cope with the occasional collision:
my $id = unpack "%32C", $name;
which is a simple checksum, or if that is too simple try:
my $crc = new Digest::CRC32();
$id = $crc->strcrc32($name);
Dirk
More information about the london.pm
mailing list