aboutsummaryrefslogtreecommitdiff
path: root/ponysaylinklist.pl
diff options
context:
space:
mode:
Diffstat (limited to 'ponysaylinklist.pl')
-rwxr-xr-xponysaylinklist.pl72
1 files changed, 72 insertions, 0 deletions
diff --git a/ponysaylinklist.pl b/ponysaylinklist.pl
new file mode 100755
index 0000000..ec6ff9b
--- /dev/null
+++ b/ponysaylinklist.pl
@@ -0,0 +1,72 @@
+#!/usr/bin/perl
+
+# ponysaylist
+# Prints a list of ponies in columns
+#
+# Licensed under WTFPL
+# See COPYING for details
+
+# Author: Mattias Andrée, maandree@kth.se
+
+
+%hash = ();
+$argc = @ARGV;
+
+$i = 0;
+while ($i < $argc)
+{
+ $source = $ARGV[$i];
+ $i += 1;
+ $target = $ARGV[$i];
+ $i += 1;
+ if ($source eq $target)
+ {
+ $hash{$source} = [ () ];
+ }
+}
+
+$i = 0;
+while ($i < $argc)
+{
+ $source = $ARGV[$i];
+ $i += 1;
+ $target = $ARGV[$i];
+ $i += 1;
+ unless ($source eq $target)
+ {
+ push @{ $hash{$target} }, $source;
+ }
+}
+
+$i = 0;
+while ($i < $argc)
+{
+ $source = $ARGV[$i];
+ $i += 1;
+ $target = $ARGV[$i];
+ $i += 1;
+ if ($source eq $target)
+ {
+ @list = @{ $hash{$source} };
+ $first = 1;
+ print $source;
+ foreach $link (@list)
+ {
+ if ($first eq 1)
+ {
+ print " (".$link;
+ $first = 0;
+ }
+ else
+ {
+ print " ".$link;
+ }
+ }
+ if ($first eq 0)
+ {
+ print ")";
+ }
+ print "\n";
+ }
+}
+