blob: 1188ba785ace228452658ea156728b4e68b6bcbc (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
#!/usr/bin/perl
# Written by Marc Espie, 2001.
# Public domain
@cycle = ();
sub show_cycle()
{
return if @cycle == 0;
$min = 'zzzzz';
for ($i = 0; $i < @cycle; $i++) {
if ($cycle[$i] lt $min) {
$minindex = $i;
$min = $cycle[$i];
}
}
@ordered=();
for ($i = $minindex; $i <@cycle; $i++) {
push(@ordered, $cycle[$i]);
}
for ($i = 0; $i < $minindex; $i++) {
push(@ordered, $cycle[$i]);
}
print join(',', @ordered), "\n";
}
while (<>) {
chomp;
if ($_ eq 'tsort: cycle in data') {
show_cycle();
@cycle = ();
} else {
m/^tsort:\s+/ and push(@cycle, $');
}
}
show_cycle();
|