in reply to help writing simple perl script

Are you looking for all unique combinations? If so, here you go...

use strict; use warnings; use Math::Combinatorics; # Get the data file name from command line. # Output filename is optional. my( $infile, $outfile ) = @ARGV; die "No filenames provided.\n" unless defined $infile; $outfile = ( defined $outfile ) ? $outfile : $infile . '.out'; # Read input data and put it in an array for later use. open my $in_handle, '<', $infile or die "Couldn't open $infile for input.\n$!"; my $dataset_aref; while ( my $number = <$in_handle> ) { chomp $number; next unless length $number > 0; push @{$dataset_aref}, $number; } close $in_handle; # Create a Math::Combinatorics object. my $combinat = Math::Combinatorics->new( count => 2, data => $dataset_aref, ); # Open an output file, and print out the combinations. open my $out_handle, '>', $outfile or die "Couldn't open $outfile for output.\n$!"; while ( my @combo = $combinat->next_combination ) { print $out_handle "@combo\n"; } close $out_handle or die "Couldn't close $outfile after output.\n$!";

Usage example:

perl mycombinat.pl data.txt data.out

data.txt should contain a '\n' delimited list of elements. data.out will contain a list of pairings. If you don't specify an output filename one will be chosen for you (the extension '.out' will be added to whatever input filename you specified).

This script uses Math::Combinatorics to find all unique combinations, two at a time. nC2.


Dave