From 70c27ca36f696b12012d7f47ac3071f747b95207 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Wed, 1 Aug 2012 03:33:30 +0200 Subject: some edits --- list.pl | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100755 list.pl (limited to 'list.pl') diff --git a/list.pl b/list.pl new file mode 100755 index 0000000..2004484 --- /dev/null +++ b/list.pl @@ -0,0 +1,41 @@ +#!/usr/bin/env perl + +# ponysaylist +# Prints a list of ponies in columns +# +# Licensed under WTFPL +# See COPYING for details + +# Author: Mattias Andrée, maandree@kth.se +# spider-mario + + +use strict; +use warnings; +use utf8; +use feature qw(say); +use integer; +use List::Util qw(max); + +my $scrw = shift @ARGV // 1; + +#for (@ARGV) { +# # Format names from pony names +# s/(?<=[a-z])(?=[A-Z])/ /; +# s/_(.*)/\t($1)/; +#} + +my $maxw = max 1, map {length} @ARGV; + +my $cols = max 1, (($scrw + 2) / ($maxw + 2)); + +my @list = map {sprintf "%-${maxw}s", $_} @ARGV; + +my $rows = (@list + $cols - 1) / $cols; + +my @rowlist; +for my $i (0 .. $#list) { + push @{$rowlist[$i % $rows]}, $list[$i]; +} + +say join ' ', @$_ for @rowlist; -- cgit