in reply to Re: What data structure is this and how to access?
in thread What data structure is this and how to access?

I'm not a fan of such simplifications. They obscure the true nature of the beast.

Calling it an "array of hashes" suggests that doing this will fail...

push @TestVals, "Monkey";

... because you're pushing something that is not a hash onto a supposed "array of hashes".

@TestVals is simply an array. It just so happens that the only item the original asker pushed onto the array happened to be a reference to a hash. But that doesn't necessarily mean that everything on @TestVals will be a hashref.

Replies are listed 'Best First'.
Re^3: What data structure is this and how to access?
by roboticus (Chancellor) on Jan 18, 2012 at 13:10 UTC

    tobyink:

    I understand what you mean. However, sometimes you have to start with a simplification to get the basic point across without complicating the environment overmuch. When we answer a question, we're frequently (consciously or not) walking a tightrope trying to balance between a simple (and somewhat deficient) answer and a longer (and more technically accurate, yet possibly more confusing) answer. External factors also come into play: for example, my time was short this morning before my commute to work, so it biased me towards shorter answers.

    In this specific case, he wanted to know the name of the structure he was creating as well as how to access the elements. So for the question asked, I think my answer is fine. Obviously, a longer answer showing the flexibility of the array, like you demonstrate, would also be fine. I just opted for the shorter answer in this case. If he posed the question differently, I might've presented an answer more like yours.

    ...roboticus

    When your only tool is a hammer, all problems look like your thumb.

Re^3: What data structure is this and how to access?
by jethro (Monsignor) on Jan 18, 2012 at 15:15 UTC

    I wouldn't call that a simplification. It really is a AoH as long as he doesn't also push a scalar or a non-hash-pointer.

    In the same way I can call a hash where the elements are linked in binary tree form a binary tree.