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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |