From 7dced5dd382ecebcde1f84a80f5f734b0fd046c2 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Tue, 24 Jul 2012 14:57:44 +0200 Subject: fix ponysay -L + fix for issue 53 --- ponysaylinklist.pl | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100755 ponysaylinklist.pl (limited to 'ponysaylinklist.pl') 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"; + } +} + -- cgit