I might not have expressed myself correctly, but I was only trying to say that, since $ref and @head are never changing in the presented code, each time through the loop, the values of @aa will clobber the previously recorded ones, so that the loop is in effect useless, it would be faster to go straight to the last line of the file, split it and run the discussed command only once. Example under the Perl debugger:

DB<1> @head = qw 'foo bar baz' DB<2> @{$ref}{@head} = qw /one two three/; DB<3> x $ref 0 HASH(0x8032f9b8) 'bar' => 'two' 'baz' => 'three' 'foo' => 'one' DB<4> @{$ref}{@head} = qw /four five six/; DB<5> x $ref 0 HASH(0x8032f9b8) 'bar' => 'five' 'baz' => 'six' 'foo' => 'four' DB<6>
The assignment of line 4 is clobbering what was previously in the hash referenced by $ref. It does not make sense to do that in a loop, since only the last assignment of the loop is useful.

Or the real code is different, in which case it might be useful to see the real code.


In reply to Re^3: Faster Hash Slices by Laurent_R
in thread Faster Hash Slices by jht

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.