in reply to Re: Re: max_strl - Get length of longest string in a hash
in thread max_strl - Get length of longest string in a hash

Like this . Pretty trivial really, once you've figured out what all the possibilities are - and writing the tests first really helps. It copes with items being deleted and with items being changed, only rescanning when absolutely necessary.

I shall now cross all my fingers and toes and hope there's no bugs :-)

  • Comment on Re: Re: Re: max_strl - Get length of longest string in a hash

Replies are listed 'Best First'.
Re: Re: Re: Re: max_strl - Get length of longest string in a hash
by liz (Monsignor) on Aug 21, 2003 at 14:12 UTC
    Looks good. But it seems that you're polluting the hash with keys KEY, VALUE, CURRENT_STATE and RESCAN_NEEDED. Although the chance that an actual application would use those keys is small, it is not 0.

    You might want to bless the object as a list ref with two hash refs: one with the actual hash info, and one with your state maintenance. That way they will never be able to interfere with each other. But this will slow down access to the hash even further though. YMMV.

    Liz

      Ahh no, CURRENT_STATE is what *really* contains the hash, and the FETCH, STORE, DELETE etc operations happen on that hash. This is effectively the same as your suggestion, as it keeps the user's data seperate from my metadata.
        You're right. I guess I should have looked closer. My bad.

        But a dereference of a list element would be faster than an extra hash lookup ;-)

        Liz