http://www.perlmonks.org?node_id=1014711


in reply to Using filepath method to identify an .html page

Do I understand correctly that you've already got a database table with a column "pin" (I assume a unique integer?) and another column "page" which contains something like the URL of the page? Why not just use that unique identifier? (Or create another database table, as other people here have suggested?)

Anyways, although I don't think this is the correct solution for your situation, here is an answer to your original question: One concept of generating a number from a string is a Hash function, however, those numbers are generally not unique. Also, int has nothing to do with hash functions (the closest built-in is probably crypt, and that's not what you want, either).

The problem with your question is this: using a hash function causes you to lose information about the original string, and the numbers you generate won't be guaranteed to be unique anymore. If you want the numbers to be truly unique, then the only way to guarantee that is to keep a list of the original strings around, which you say you don't want to do because of the amount of data that means. Sorry, you can't have it both ways...

But maybe we're not quite understanding your existing set-up or what your goal is?

  • Comment on Re: Using filepath method to identify an .html page

Replies are listed 'Best First'.
Re^2: Using filepath method to identify an .html page
by Nik (Initiate) on Jan 22, 2013 at 16:13 UTC
    Read this please, so to clarify what i need to do

    http://www.perlmonks.org/?node_id=1014708