Doesn't seem to be anything that does exactly what you want. Expanding on tanktalus's responses, I offer the following:
sub unzip(&@) { my $code = shift; my @retlist; while(@_) { local $_ = \@_; push @retlist, $code->(); } return @retlist; } use Data::Dumper; my %h = qw(k1 v1 k2 v2); print Dumper [unzip {[shift @$_,shift @$_]} %h];
This one will work regardless of the number of items accessed in the code block, because those items are shifted out as the sub works. However, it requires that you refer to the items using shift @$_ rather than your preferred $_[0], etc. Also, this method will preserve the order of a list if invoked on a genuine list rather than a hash.
sub unzip(&\%) { my $code = shift; my %hash = %{shift()}; my @retlist; while(my @list = each %hash) { push @retlist, $code->(@list); } return @retlist; } use Data::Dumper; my %h = qw(k1 v1 k2 v2); print Dumper [unzip {[$_[0], $_[1]]} %h];
This one matches your desired syntax exactly, but will only work for hashes, that is the argument %h must be a hash. Also, since it's a hash the order of the result is undefined (as is the standard behavior of each).

In reply to Re: functional opposite of zip by bellaire
in thread functional opposite of zip by Anonymous Monk

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.