NAME
List::Zip - Module to zip and unzip lists.
DESCRIPTION
Provides subroutines to zip and unzip lists. Each subroutine provided returns a list formed from the input lists.
List::MoreUtils also provides functionality to mesh
lists. However, this implementation differs. If the lists passed to zip
or unzip
have different sizes all the the lists will be truncated to the same size as the smallest list.
SYNOPSIS
use List::Zip;
my @zipped = List::Zip->zip(
[ 1, 2, 3, 4, 5 ], [ 'one', 'two', 'three', 'four', 'five' ]
);
say $zipped[0]->[0]; # 1
say $zipped[0]->[1]; # one
say $zipped[1]->[0]; # 2
say $zipped[1]->[1]; # two
my @unzipped = List::Zip->unzip(@zipped);
say for @{ $unzipped[0] }; # 1 2 3 4 5
say for @{ $unzipped[1] }; # one two three four five
METHODS
zip
Converts this list by combining corresponding elements from the input lists into lists.
my $zipped = List::Zip->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 ]
unzip
Converts this list into multiple lists, each containing the corresponding elements from each of the input lists.
my @unzipped = List::Zip->unzip(
[ 1, 'one', 'a' ], [ 2 , 'two', 'b' ], [ 3, 'three', 'c' ]
);
The structure of the list returned by unzipping the above is:
[ 1, 2, 3 ], [ 'one', 'two', 'three' ], [ 'a', 'b' ,'c' ]
EXPORTS
None. Methods provided by this module are class methods so should be invoked by the class.
List::Zip->zip(@lists);
List::Zip->unzip(@lists);
SEE ALSO
AUTHOR
Lloyd Griffiths
COPYRIGHT
This software is copyright (c) 2014 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.