The right-hand side of an assignment is always evaluated before the left-hand side. (This is what allows for chained assignments, like $x = @y = 7.) In your first snippet, you create a reference to an array, then shift the first value off the same array. In the second snippet, however, you create a new array with the first three elements of the original array, and then shift the first value off the old array.

I think this situation is not best handled with a single line of code:

my $key = shift @array; $test{$key} = [ @array[0,1,2] ];
BTW, \@{ [ LIST ] } creates a reference to an anonymous array, dereferences the reference to the anonymous array, and then creates a new reference to the anonymous array. That's a bit silly... :)

In reply to Re: i thought i understood shift... by chipmunk
in thread i thought i understood shift... by jptxs

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.