in reply to Re: Get all hash value into array
in thread Get all hash value into array

> I suggest "flattening" your hierarchical structure to a flat table.

Your approach implies that the data is essentially analog to a DB table. But you are losing the possibility to index the data by "zip" (?) or "state" with a hash lookup.

> Searching a table like that is simple,

I don't see why using 3 nested while each loops are more complicated. It's pretty generic and keeps all data available. (Though you have to take care not to mess up the each iterator)

> but does cost in performance because you have to examine each row for every search.

Hmm, if I wanted to represent a DB table I'd use an AoA with associated index hashes.

I'm pretty sure this can already be found° on CPAN.

Probably as object or tied array.

I'm not very experienced with NoSQL but this might go into the same direction.

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

°) a cursory look revealed Data::Table not sure if that's a good example though.

Replies are listed 'Best First'.
Re^3: Get all hash value into array
by Marshall (Canon) on Feb 13, 2020 at 08:43 UTC
    Hi Rolf!

    Your approach implies that the data is essentially analog to a DB table.
    But you are losing the possibility to index the data by "zip" (?) or "state" with a hash lookup.

    My approach not only implies a "flat", "de-normalized" DB table, that is what it is. This will work great for a few ten's of thousands of lines. I am not "losing the possibility to index by "zip"". When you get to say 100,000K+ lines, then I would recommend a DB like SQLite. Let the DB take care of indexing. There are to be sure a lot of "if's, and's and but's" with a DB. However the OP's data structure does not appear to me to be efficient.

    From what I can tell, the use of the "zip" as a primary key doesn't make any sense. And the OP's hash structure is hard to search and inefficient. Yes, I do think that 1 loop is easier to understand than 3 loops.
    Cheers, Marshall