stevieb++ and johngg++ have explained the problem and its solution, but note also that this feature (yes, feature) is called "list flattening". Any lvalue array (or hash) in a list assignment will consume all remaining items in the assigned (RHS) list.

c:\@Work\Perl\monks>perl -wMstrict -MData::Dump -e "my ($w, $x, @y, @z); ($w, $x, @y, @z) = qw(Dubya Eks Why? Zee-List-Is-Flattened); dd 'w', $w; dd 'x', $x; dd 'y', \@y; dd 'z', \@z; " ("w", "Dubya") ("x", "Eks") ("y", ["Why?", "Zee-List-Is-Flattened"]) ("z", [])
Try this with  %y (a hash) in place of the  @y array, and with any combination of scalar(s), array(s) or hash(s) in place of the  @z array.

BTW, in the category of Stupid Hash Tricks, try this:

c:\@Work\Perl\monks>perl -wMstrict -le "my %hash = (4 => 12, 34 => 102); ;; while (my %h = each %hash) { printf qq{%s => %s \n}, %h; } " 4 => 12 34 => 102

Update: A solution using assignment to an array (update: could also be a hash %kv) (also not recommended) might be something like:

c:\@Work\Perl\monks>perl -wMstrict -le "my %hash = (4 => 12, 34 => 102); ;; while (my @kv = each %hash) { local $, = ' => '; print @kv; } " 4 => 12 34 => 102
(Update: In adding this Update, I screwed up the previous BTW example code. Everything's fixed now.)


Give a man a fish:  <%-{-{-{-<


In reply to Re: Output of hash by AnomalousMonk
in thread Output of hash by catfish1116

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.