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

Maybe I'm missing something here, but it seems to me that this would be a good Perl intepreter flag... i.e., that all associate array keys should be treated case-insensitively. The interpreter would implicitly run "lc" when computing the hash value for storing or retrieving a value.

The background here, as I alluded to above, is that I've got about 20,000 lines of code for a web system. Alot of my application is database-driven, and I have a module that just contains functions to retrieve rows from numerous tables.

The mechanism for returning data from the retrieve functions is a pointer to a hash table (of the returned row). The keys in the hash are case-sensitive names of the fields. So the risk here is that someone who maintains this code makes a change and typos a hash key. Unlike with using strict vars, where Perl warns you if it thinks you've made a typo in a variable name, it would be very difficult to track down a typo in a hash key.

Any other thoughts?

thanks
MFN

Replies are listed 'Best First'.
Re^3: case-insensitive hash keys
by BrowserUk (Patriarch) on Aug 22, 2004 at 03:14 UTC

    How many functions are there return hashrefs? Is it a great big deal to tie the hashes before filling and returning them?


    Examine what is said, not who speaks.
    "Efficiency is intelligent laziness." -David Dunham
    "Think for yourself!" - Abigail
    "Memory, processor, disk in that order on the hardware side. Algorithm, algorithm, algorithm on the code side." - tachyon
      About 60 functions. So its a good chunk of work, but probably worth it for the maintainability. What's the efficiency/speed of using tied hashes vs. regular hashes? (this is for a high-volume web application.) thanks MFN

        Tied hashes are somewhat slower than regular ones, but if your filling the hashes from a RDBMS then the time taken to get the data will far outweight the speed of access once you have got it.


        Examine what is said, not who speaks.
        "Efficiency is intelligent laziness." -David Dunham
        "Think for yourself!" - Abigail
        "Memory, processor, disk in that order on the hardware side. Algorithm, algorithm, algorithm on the code side." - tachyon