in reply to help writing simple perl script

Here is some simple code to do it. Put it in a file and redirect the output to list.txt (e.g. foo.pl>list.txt).
use strict; my @arr = <STDIN>; map chomp $_, @arr; foreach my $i (0..$#arr){ foreach my $j (0..$#arr){ print "$arr[$i] $arr[$j]\n" if $i != $j; } }
Smaller versions surely exist...

Update: If you want to read from list.txt use

foo.pl<list.txt

Replies are listed 'Best First'.
Re^2: help writing simple perl script
by ashylarry (Initiate) on Jul 27, 2006 at 20:06 UTC
    Actually this one almost gets me all the way there, but ends up printing out a lot of redundancy. I only want any given pair of numbers to appear only ONCE in the output (regardless of the order).

    In other words, for 4 numbers, instead of:

    1 2
    1 3
    1 4
    2 1
    2 3
    2 4
    3 1
    3 2
    3 4
    4 1
    4 2
    4 3

    ...I'd want the output to be:

    1 2
    1 3
    1 4
    2 3
    2 4
    3 4

    Is there a way to do this without using the Math::Combinatorics module (I don't have permissions to install Perl modules, and hate having to go through our IT admin, so would like to avoid this if possible)

      Ahh, ok, different problem. Just change the inner loop to
      foreach my $j ($i..$#arr){
Re^2: help writing simple perl script
by ashylarry (Initiate) on Jul 27, 2006 at 16:50 UTC
    awesome! This one works great. Thanks so much!