in reply to when to use lists/hash vs references?

Not the only, and maybe not the most important, but here's one reason. The extra dereference costs:

c:\test>p1 @a = map[1..3],1..1e6;; $r = \@a;; cmpthese -1, { a=>q[ ++$a[$_][1] for 0..$#a ], b=>q[ ++$r->[$_][1] for 0..$#$r ] };; Rate b a b 3.94/s -- -16% a 4.72/s 20% --

Another is that the extra syntax can get unwieldy for involved expressions.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
RIP an inspiration; A true Folk's Guy

Replies are listed 'Best First'.
Re^2: when to use lists/hash vs references?
by chromatic (Archbishop) on Jul 16, 2010 at 00:30 UTC
    The extra dereference costs...

    So does the stack manipulation to pass or return a large list.

      Of course. So don't do that.

      Declare an array, and pass a reference.

      I also prefer to use

      sub arrayManip { our @a; local *a = shift; # do stuff with @a } my @array = (...); arrayManip( \@array );

      But you doubtless consider that too "complex".

        But you doubtless consider that too "complex".

        I consider it a silly micro-optimization, because the programs I write tend to do IO. (And did you benchmark the cost of accessing the symbol table versus a lexical variable?)