```{index} single: mesh (List::Util) ``` ```{index} single: List::Util::mesh ``` # 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 ```perl 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 ```perl 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 croaks `Expected an ARRAY reference to mesh`. - Empty input list returns an empty list. - The elements are copies: modifying them leaves the inputs alone. ## Differences from upstream A hole in an input array reads as `undef`, where perl5 crashes. ## See also - `mesh_shortest` - stop at the shortest input. - `zip` - same lockstep walk, but yields one arrayref per row.