String::OrderedCombination - An algorithm to calculate all the strings resulting from an ordered combination of k characters from n characters available.
use String::OrderedCombination qw(ocombination); my @array=ocombination("foo",2); print "$_ " foreach (@array); #prints of fo of fo oo oo my @array=ocombination("bar",3); print "$_ " foreach (@array); #prints abr arb rab rba bra bar
From a set of n elements, given an integer k, the algorithm calculates k! * n!/(k!(n-k)!) elements that are all the ordered combinations of k elements from the set of n elements. I.e. the permutation x combination cross product for any given k < n.
The combination function needs a string (every character is an element of the set of n=length(string) elements) and an integer value that is k.
The function returns a list of values.
If the function returns an empty list, an error has occured and you can retrive its description from $String::OrderedCombination::err .
Thanks to Allen Day <allenday atsign ucla dotsign edu> to point me about the ordered type of combination this module performs.
The C algorithm and code is by Andrea Gasparri, the XS glue is by Dree Mistrut with a help from dada <dada atsign perl dotsign it>.
Copyright 2004,2005 Andrea Gasparri <andrea atsign slack dotsign z00 dotsign it> and Dree Mistrut <dree atsign friul dotsign it>.
Mantainer of the code is Davide Bergamini, <davidebe75 atsign yahoo dotsign it> under the authorization of Dree Mistrut <dree atsign friul dotsign it>.
This package is free software and is provided "as is" without express or implied warranty. You can redistribute it and/or modify it under the same terms as Perl itself.
To install String::OrderedCombination, copy and paste the appropriate command in to your terminal.
cpanm
cpanm String::OrderedCombination
CPAN shell
perl -MCPAN -e shell install String::OrderedCombination
For more information on module installation, please visit the detailed CPAN module installation guide.