in reply to help writing simple perl script
A brute force approach, as you indicated, would iterate across the same array in a nested fashion. You would perhaps use code like this (untested):
use strict; use warnings; my $fh; unless (open($fh,"</path/list.txt")) { die "Cannot open file: $!\n"; } my @number_array = (); while (<$fh>) { push @number_array, $_; } for (my $i=0;$i<$#number_array;$i++) { for (my $j=$i+1;$j<=$#number_array;$j++) { print $number_array[$i], "\t", $number_array[$j], "\n"; } }
Update: fixed error in outer loop -- only needs to iterate up to (n-1)th array index.
|
|---|