List::Zip - Module to zip lists.
Provides functionality to zip list structures.
List::MoreUtils also provides functionality to mesh
lists. However, this implementation differs. If the lists provided have different sizes all of the the lists will be truncated to the same size as the smallest list.
use List::Zip qw(zip zip_with);
my @zipped = zip([ 1, 2, 3, 4, 5 ], [ 'one', 'two', 'three', 'four', 'five' ]);
my @unzipped = zip(@zipped);
my @zipped_with = zip_with([ 1, 2, 3 ], [ 4, 5, 6 ] => sub { return $_[0] + $_[1] });
Converts this list by combining corresponding elements from the input lists into lists.
my @zipped = zip([ 1 .. 5 ], [ 6 .. 10 ]);
The structure of the list returned by zipping the above is:
([ 1, 6 ], [ 2, 7 ], [ 3, 8 ], [ 4, 9 ], [ 5, 10 ])
Converts this list by combining corresponding elements from the input lists into lists. The given function is applied to each combination of the corresponding elements.
my @zipped = zip_with([ qw(t f r f) ], [ qw(h a e o) ], [ qw(e t d x) ] => sub {
return join '', @_;
});
The structure of the list returned by zipping with the above function applied is:
('the', 'fat', 'red', 'fox')
None by default.
Lloyd Griffiths
This software is copyright (c) 2014-2016 by Lloyd Griffiths.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.