Print

Print


If your only purpose is to name the files, do you need a "globally" unique ID? Why not just use an increment, along with the author & first letter.

e.g.

>  Aeschylus / Prometheus Bound => aeschylus_p01.txt
>  Aeschylus / Suppliant Maidens => aeschylus_s01.txt
>  American State / Articles of confederation => american_state_a01.txt
> ...
>  Aristotle / On Generation And Corruption => aristotle_o01.txt
>  Aristotle / On The Gait Of Animals => aristotle_o02.txt
>  Aristotle / On The Generation Of Animals => aristotle_o03.txt

If you generate your integers in alphabetical order, they'll always be the same for each title and you'll never get filename collisions. Unless your list will grow - will it?

-Andrew


On 2010-05-28, at 9:34 AM, Eric Lease Morgan wrote:

> 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