On Thu, 2007-08-30 at 00:49 +0200, Michael Holzt wrote: > > or even > > 10 + 1 + 16 + 1 + 39 + 1 + 5 + 1 + 39 + 1 + 5 = 119 characters > > Better encode it binary. E.g. for IPv4:
And better get the number of bits correct. An IP address is a 32 bit integer, not 15 characters. Although perl converts scalars on-demand, it correctly preserves integer values. > > my $id = pack("NCNNNN",$$,$start,$lip,$lport,$rip,$rport) I thought port numbers had been pretty much refuted already. If not, it would help to add a requirement to the list and explain why they provide the best solution. > > Sum: 21 Bytes. Encoded in Base64: 28 Bytes. For discussion, I started using sprintf("0#x%- ... ") since I expect my logs to be text and this looks like a UUID. The number of bits is just 4* the number of characters. It is simple enough to switch to pack or base64 later or use pack as an option for those who want binary logs. So far no-one has come up with much objection to sprintf("%08x-%08x-%04x",gettimeofday,$$) This satisfies requirements (1) and (4) and Matt says it works for him. If we need a 16-bit, RCPT counter, req (2), then: sprintf("%08x-%08x-%04x-%04x",gettimeofday,$$,$RCPT) If we need a host ID, req (3), then using IP-Addr (IPv4 only): sprintf("%0x8-%0x8-%04x-%04x-%08x",gettimeofday,$$,$RCPT,$IP) though I think a substring of config('me') might do the job and would be IPv-agnostic. At this point we are at 128 bits (8 bytes) - same as UUID. -- --gh