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$!";