unpairs#
Flatten a list of two-element arrayrefs into a key/value list.
Synopsis#
my @kvlist = unpairs @pairs;
my %hash = unpairs @pairs;
What you get back#
A flat list with exactly two elements per input arrayref: copies of [0] as the key and [1] as the value. Missing elements pad with undef so that the result is always even-sized; an argument that is not an ARRAY reference croaks.
Examples#
my @kv = unpairs [a => 1], [b => 2]; # ('a', 1, 'b', 2)
my %h = unpairs pairs %other; # round-trip
my @kv = unpairs sort { $a->[0] cmp $b->[0] } pairs %h;
Differences from upstream#
A plain integer argument croaks Not a reference where perl5 crashes, and an array reference held in a variable that once held a string is accepted where perl5 refuses it.
See also#
pairs- the inverse direction.