in reply to problem with loop
Hi,
probably something like this:
#!/usr/bin/perl use strict; use warnings; use 5.010; my @list = qw(PA5098 PA5100 PA5092 PA3175); for (my $i = 0; $i < @list - 1; $i++) { for (my $j = $i + 1; $j < @list; $j++) { my $diff = $j - $i; print "$list[$i] $list[$j] $diff\n"; } }
Be aware: You need a special case when list has less than two elements.
Regards
McA
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: problem with loop
by AnomalousMonk (Archbishop) on Oct 27, 2014 at 13:51 UTC | |
|
Re^2: problem with loop
by Anonymous Monk on Oct 27, 2014 at 11:53 UTC |