data structures - What is better in Perl: an array of hash references or list of "flat" hashes? -


I can not decide which approach is more (1) idiomatic pearl, (2) efficient, or (3)

Let me explain by code. First of all, I

  sub somewhat {... $ ref-> gt; {Size} = 10; $ Ref-> {Name} = "Foo"; $ Ref-> {Volume} = 100; Push (@ references, $ ref); ... Reference @ Return; }  

Or, I can

  sub something {... push (@ name, "foo"); $ Size {Foo} = 10; $ Volume {fu} = 100; ... Return (\ nname, \% size, \ version%); }  

Both essentially do the same thing. The important thing is that I need an array, because I need to place an order.

I know, there is always more than one way to do anything, but still, do you like any of these?

Instead of thinking in words without meaning, some , think and phrase Issues in Solid Conditions In this case, you are returning a list of objects that have names , size and quantity attributes. When you think of it in this way, there is no reason to consider the second method.

After you run into problems, you can think of optimization later, but if you do this, then you probably will be more benefited by the explosion of data structures.

Improving Efficiency I would recommend returning a reference from this subroutine:

  sub get_objects {my @ret; While ('some condition') {# Should I return it? Push @rate, {name = & gt; 'Foo', Size = & gt; 10, volume = & gt; 100,}; } Return \ @rot; }  

Comments

Popular posts from this blog

c# - ListView onScroll event -

PHP - get image from byte array -

Linux Terminal Problem with Non-Canonical Terminal I/O app -