diff options
author | Pablo Lezaeta <prflr88@gmail.com> | 2012-07-23 16:31:30 -0400 |
---|---|---|
committer | Pablo Lezaeta <prflr88@gmail.com> | 2012-07-23 16:31:30 -0400 |
commit | 267dfe92e97f637f15b5860314a73683b046b252 (patch) | |
tree | 721412cb9ec92200af7dfcc273f708e588469ef9 /ponysaylinklist.pl | |
parent | ceeb43dbac20c103bbd968cda0e2fc1f29d21341 (diff) | |
parent | 2ecc64cb70bef93e522924460e9debf3127cbfa6 (diff) | |
download | ponysay-267dfe92e97f637f15b5860314a73683b046b252.tar.gz ponysay-267dfe92e97f637f15b5860314a73683b046b252.tar.bz2 ponysay-267dfe92e97f637f15b5860314a73683b046b252.zip |
Merge branch 'master' of http://github.com/erkin/ponysay
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"; + } +} + |