|
I'm not a programmer, so I need some help with a task I need to accomplish. Hopefully one of you perl experts out there can help me out here.
I have a file containing about 1000 or so large, out of sequence numbers in a single column that I need to do the following with:
Convert the list of numbers:
125
23
291
95
5
etc...
to a two-column list of all possible number pairings:
125 23
125 291
125 95
125 5
23 291
23 95
23 5
291 95
291 5
95 5
etc...
Can anyone provide me a script that would do this? I know it would involve putting the numbers into an array and then iterating over the array in a nested loop, but I have no idea how to actually code this.
Thanks in advance!!
|
|
|
Something like this would work.
assuming the numbers are in a file called test.input.
If you don't want the number to pair with itself you have to do a bit more work. but you weren't really clear on that point.
#!/usr/bin/perl
open FILE, "< test.input" or die "Can't open file";
my @f = <FILE>;
close F;
foreach ( @f ) {
chomp;
$outer = $_;
foreach ( @f ) {
chomp;
print "$outer $_\n";
}
}
|
|
|
|
|
|
|
|