Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

Re: Algoritm for converting string to number?

by Old_Gray_Bear (Bishop)
on Aug 23, 2011 at 09:09 UTC ( #921847=note: print w/replies, xml ) Need Help??

in reply to Algoritm for converting string to number?

If this were my problem, I'd be reaching for a database immediately. My first column is the key and consists of your character string; the second column is a monotonically increasing INT of the longest precision I can get.

Almost any other 'algorithmic-mapping' solution is going to give you fits down the line when your mapping scheme encounters strings that generate integers that won't fit into your remote system's idea of INT. (Now if this is just a one-off to help get converted away from that silly system, go ahead with the algorithmic mapping, it's going to be less resource-intensive.)

But, if it were me, I'd still go with the database, though (SQLite probably). One-Offs have a nasty habit of hanging around for a long time....

Update -- corrected first word =~ /I/If/

I Go Back to Sleep, Now.


  • Comment on Re: Algoritm for converting string to number?

Replies are listed 'Best First'.
Re^2: Algoritm for converting string to number?
by raybies (Chaplain) on Aug 23, 2011 at 13:03 UTC
    Couldn't you do the same thing with just a regular Perl hash? (with the string being the key, and a global big int incremented as a unique value?)

        Okay, so not so simple, but I'd probably use...

        use Storable qw(store retrieve);

        and store and retrieve the hash once I was done with it, or needed it again.

        I'd also probably stuff the global value incrementor into some hash string and store it in the hash with a key value like, "Global Incrementing Hash Key Thingy".

        Of course Storable has its issues too...

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://921847]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2018-05-26 08:36 GMT
Find Nodes?
    Voting Booth?