diff options
author | Mattias Andrée <maandree@operamail.com> | 2012-07-18 19:39:04 +0200 |
---|---|---|
committer | Mattias Andrée <maandree@operamail.com> | 2012-07-18 19:39:04 +0200 |
commit | b5868da56c55ff0ce051b328f45470c8b0653ca4 (patch) | |
tree | d5f64922ae4f7c085fd878d793609ae24db540c2 /ponysaylist.pl | |
parent | 494dbd1eb5a2ab9ebaa323d34061722fee3986af (diff) | |
download | ponysay-b5868da56c55ff0ce051b328f45470c8b0653ca4.tar.gz ponysay-b5868da56c55ff0ce051b328f45470c8b0653ca4.tar.bz2 ponysay-b5868da56c55ff0ce051b328f45470c8b0653ca4.zip |
flewless `ponysay -l`
Diffstat (limited to 'ponysaylist.pl')
-rwxr-xr-x | ponysaylist.pl | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/ponysaylist.pl b/ponysaylist.pl new file mode 100755 index 0000000..7a09376 --- /dev/null +++ b/ponysaylist.pl @@ -0,0 +1,67 @@ +#!/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 + + +$first = 1; +$scrw = 1; +$maxw = 1; + +foreach $arg (@ARGV) +{ + if ($first == 1) + { $first = 0; + $scrw = $arg; + } + else + { $w = length $arg; + $maxw = $w if ($w > $maxw); + } +} + +$cols = int (($scrw + 2) / ($maxw + 2)); +$cols = 1 if ($cols < 1); + + +@list = (); + +$first = 1; +$items = 0; +foreach $arg (@ARGV) +{ + if ($first == 1) + { $first = 0; + } + else + { $ws = $maxw - (length $arg); + push @list, $arg.(" "x$ws); + $items += 1; + } +} + + +$rows = int (($items + $cols - 1) / $cols); +$i = 0; +@rowlist = (); + +while ($i < $items) +{ $row = 0; + while (($row < $rows) and ($i < $items)) + { + $rowlist[$row] .= " " unless ($i < $rows); + $rowlist[$row] .= $list[$i]; + $row += 1; + $i += 1; +} } + +foreach $row (@rowlist) +{ + print $row."\n"; +} + |