larryk has asked for the wisdom of the Perl Monks concerning the following question:

I've written a script to parse Apache logs containing cookie data. It enables me to count the number of users and the number of requests they made by populating a hash as I iterate through the log (e.g. $users{$cookie}++;).

The problem I have got is that, because I am using the cookiestring as the hash key it is of unknown length. Now, the only cookie that we set is ~ 30-40 characters but I have run across a couple of instances where Netscrape has dumped the entire cookie file instead of just returning our one. One particular instance led to a would-be key length of ~ 3.5Kb - would-be if SDBM had not shat its pants and ran away crying like a baby!

Is this a bug in SDBM or is there a max key length? If it is SDBM then does anyone know whether any of the other DBM implementations suffer from this problem.

p.s. I am not sitting here wondering how to shorten the string - just curious as to the key length issue.

Replies are listed 'Best First'.
Re: SDBM or Perl hash key length restrictions
by kschwab (Vicar) on Mar 26, 2001 at 19:50 UTC
    From the BUGS section of the SDBM docs:

    There are a number of limits on the size of the data that you can store in the SDBM file. The most important is that the length of a key, plus the length of its associated value, may not exceed 1008 bytes.

    My suggestion would be to use DB_File or BerkeleyDB, both of which are based on the Berkeley DB Library, and should be free of arbitrary limits.

    Another option would be GDBM_File, which uses the GNU Dbm library.

      Thank you. That is exactly what I wanted to know.
    A reply falls below the community's threshold of quality. You may see it by logging in.