in reply to Re: case-insensitive hash keys
in thread case-insensitive hash keys

Good idea, but this would be as a modification to a set of Perl scripts that use hashes extensively, with approx. 20,000 lines of code. :S So, I guess I'm looking for something that doesn't require that much modification as inserting the lc() function everywhere.

Replies are listed 'Best First'.
Re^3: case-insensitive hash keys
by Limbic~Region (Chancellor) on Aug 21, 2004 at 00:45 UTC
    ManFromNeptune,
    Hash::Case::Preserve, in the same family as the module suggested by Zaxo, does case insensitive keys while maintaining the original case. The thing is you have to tie the hash using this module. There is no magic way to say "treat all hashes in this program as case insensitive".

    Cheers - L~R

      Ok, this is a potential solution. However (final neurosis question), I'm concerned about speed. Alot of tied hashes are going to be created in the context of a single web hit. Isn't that going to be slower than using regular hashes? (I suppose this is a classic tradeoff issue: raw speed vs. maintainability.)

      thanks all,
      MFN

        Please don't concern yourself with that ahead of time. If you write the code and find it to be too slow, then profile it to find out where the real bottleneck is. Programmers are notoriously useless in predicting which parts of their code will consume the most time, so concentrate on constructing something correct, readable, maintainable, simple, clear, and only concern yourself with speed once you find that performance is insufficient. Then, measure which part of your code actually needs acceleration, and work on that. Chances are it will be something completely different than what you expected.

        It is easier to optimize correct code than to correct optimized code.

        Makeshifts last the longest.

        ManFromNeptune,
        Hash keys are case sensitive. To make something that looks and feels like a hash, but is case insensitive takes overhead. There is no way to get around that.

        It might be worth while to keep in mind that your approach to solving a problem is unlikely to be the same as people with more experience. If you only ask how to accomplish your approach without stating the underlying problem, we are locked in without anyway of providing better, alternative advice.

        Cheers - L~R

Re^3: case-insensitive hash keys
by cyocum (Curate) on Aug 21, 2004 at 00:27 UTC

    I have not thought this through completely, but you could use a tied hash which on STORE used a lowercase function. This would alleviate the need to have a lc() all over the code but it would slow your code down a bit. Again, this is off the top of my head so it might not work.