mesh#

Interleave multiple arrays, padding shorter ones with undef.

Registered under both mesh and mesh_longest. Both forms stop at the length of the longest input and fill missing elements with undef.

Synopsis#

my @out = mesh         \@a, \@b, \@c;
my @out = mesh_longest \@a, \@b, \@c;
my %h   = mesh \@keys, \@values;

What you get back#

A flat list containing elements at position 0 from each input array, then position 1, and so on, up to the longest input. Missing positions are filled with undef.

Examples#

my @r = mesh [1..3], ['a'..'c'];          # (1,'a', 2,'b', 3,'c')
my @r = mesh [1..3], ['a'..'b'];          # (1,'a', 2,'b', 3,undef)
my %h = mesh \@keys, \@values;            # build a hash

Edge cases#

  • An input that is not an arrayref contributes only undefs.

  • Empty input list returns an empty list.

Differences from upstream#

Fully compatible with upstream.

See also#

  • mesh_shortest — stop at the shortest input.

  • zip — same lockstep walk, but yields one arrayref per row.