-----Original Message-----
>From: Eric Lease Morgan <[log in to unmask]>
>Sent: May 28, 2010 9:34 AM
>To: [log in to unmask]
>Subject: [CODE4LIB] generating unique integers
>
>Given a list of unique strings, how can I generate a list of short, unique integers?
>
>I have a list of about 250 unique author/title combinations, such as:
>
> Aeschylus / Prometheus Bound
> Aeschylus / Suppliant Maidens
> American State / Articles of confederation
> American State / Declaration of Independence
> Aquinas / Summa Theologica
> Aristophanes / Achamians
> Aristophanes / Clouds
> Aristophanes / Ecclesiazusae
> Aristotle / On Generation And Corruption
> Aristotle / On The Gait Of Animals
> Aristotle / On The Generation Of Animals
> ...
>
>From each author/title combination I want to create a file name (key). Specifically, I want a file name with the following form: author-firstwordofthetitle-integer.txt Such a scheme will make it (relatively) easy for me to look at the file name and know the what title is and by whom.
>
>Using Perl, how can I convert the author/title combination into some sort of integer, checksum, or unique value that is the same every time I run my script? I don't want to have to remember what was used before because I don't want to maintain a list of previously used keys. Should I use some form of the pack function? Should I sum the ASCII values of each character in the author/title combination?
>
>--
>Eric Morgan
Summing ASCII values in the characters might work most of the time, but will likely get instances where the numbers are not unique.
This might be really simpleminded, but why not just increment by 1 an index number and use that for integer in the filename? That way you know that the number generated will be unique every time you run the script, and you only have to remember the last used key -- not the whole list of previously used keys. The disadvantage is that you would be using up integers indefinitely, and there is a limit, but perhaps that might be good enough.
Peter Schlumpf
|