diff options
author | Pablo Lezaeta <prflr88@gmail.com> | 2012-07-23 16:33:06 -0400 |
---|---|---|
committer | Pablo Lezaeta <prflr88@gmail.com> | 2012-07-23 16:33:06 -0400 |
commit | 0097a6134b0d7697a37928633bb5c7cfef0df9ff (patch) | |
tree | ded2d7f9fdda22ba077d27339f7c3bf2601d6cb1 /ponysaylinklist.pl | |
parent | cc1ff7fa58be547cb0714cba5e78ad72f95bd273 (diff) | |
parent | 267dfe92e97f637f15b5860314a73683b046b252 (diff) | |
download | ponysay-0097a6134b0d7697a37928633bb5c7cfef0df9ff.tar.gz ponysay-0097a6134b0d7697a37928633bb5c7cfef0df9ff.tar.bz2 ponysay-0097a6134b0d7697a37928633bb5c7cfef0df9ff.zip |
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'ponysaylinklist.pl')
-rwxr-xr-x | ponysaylinklist.pl | 72 |
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"; + } +} + |