If you really don't like the temporary array - doesn't seem so bad to me - you could use something like:

my $i = 0; # or whatever $record[$i++]->{bytes} = $_ for get_bytes($num);

or perhaps, if you're just building the list:

push @record, map { {bytes => $_} } get_bytes($num);

but that won't be much good if you're working with an existing data structure. In that case i don't see a way of shrinking it to one line - and suspect that even if you find one, you'd regret the obfuscation later.

update just tried mr robot's solution and found, to my surprise, that the double curlies aren't required. I would have expected

@a = map { k => $_ } (1..3);

to give you (k,1,k,2,k,3), but no: it creates an array of hashrefs. so either that isn't a block at all - but where's the comma? - or there is such a thing as hash context after all. nice bit of dwimming. still borks any other key that previously existed in the hash, though.

update^2 don't know what i was thinking there. sauoq is quite right. odd that i remember it working, but clearly it doesn't :(


In reply to Re: variable list assignment by thpfft
in thread variable list assignment by arc_of_descent

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.