my %hash = ('a'=>'test'); my @arr = ($hash{'a'}); print \$hash{'a'}."\n"; print \$arr[0]."\n";
How can I do something like that, except re-use the same data rather than create a copy (same reference, not just same value)? I assume that would be faster? I know I can put the reference in the array, but the values need to be in the array so they can be passed to printf. The size of the array and the keys in the hash will vary. This code will be iterated millions of times, so I want it as fast as possible. The hash won't be used once the array is created, so I'm not concerned about the hash values being modified when the array values are.

In reply to push to array without copying by chris212

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.