in reply to Dotted hash access

As you pointed out yourself, it looks just as crazy in C. In C, and probably several other languages, people tend not to write such deep structures (in my experience anyway), if you don't like it in Perl, why do it there then? Whats stopping you from having a hash called Locations, in which you store the location names (ids, or whatever they were), and another hash called Buildings in which you store the cost? (Plus a third one that tells you which Building is at which Location).

Oops, strange, that's how I'd do it were I using a database..

Nothing says you have to put all your data in one huge data structure. Your idea sounds like a nice one, until you realise the restrictions, and that its an elaborate way of getting around not using a DB or a DB-like structure. Theres no need to use a huge DB just use SQLite or something?

C.

Replies are listed 'Best First'.
Re^2: Dotted hash access
by sfink (Deacon) on Nov 25, 2004 at 09:48 UTC
    I guess I really should have described the data set better. Every level of that tree is fully populated. I can't have a separate table of buildings, because those buildings are specific to the given location. In database terms, both the location and the building name are in the primary key. (I do have a separate table of buildings, but that's in a separate data structure and describes the features they have in common.) I guess "cost" was a bad example to use, since it's unclear why it would vary by location. My bad.

    I guess what I'm saying is that I periodically run across cases where the data is fundamentally deeply nested, and I need to start over from a fairly high level frequently (so I can't just grab the nested hash out and pass it into the other functions, avoiding long lookup chains.) Admittedly, it's not a frequent occurrence, but configuration files and simulations seem to be typical examples.

      I understand what you're trying to say, I still can't think of an actual use that wouldn't lend itself to splitting in this manner. It's just a design issue.

      C.