2012-07-24 14:24:23 +00:00
|
|
|
#!/usr/bin/env perl
|
2012-07-18 17:39:04 +00:00
|
|
|
|
|
|
|
# ponysaylist
|
|
|
|
# Prints a list of ponies in columns
|
|
|
|
#
|
|
|
|
# Licensed under WTFPL
|
|
|
|
# See COPYING for details
|
|
|
|
|
|
|
|
# Author: Mattias Andrée, maandree@kth.se
|
|
|
|
|
|
|
|
|
2012-07-24 14:24:23 +00:00
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
use utf8;
|
|
|
|
use feature qw(say);
|
|
|
|
use integer;
|
|
|
|
use List::Util qw(max);
|
2012-07-18 17:39:04 +00:00
|
|
|
|
2012-07-24 14:24:23 +00:00
|
|
|
my $scrw = shift @ARGV;
|
|
|
|
|
|
|
|
for (@ARGV) {
|
2012-07-21 07:36:33 +00:00
|
|
|
# Format names from ponyies names
|
2012-07-24 14:24:23 +00:00
|
|
|
s/(?<=[a-z])(?=[A-Z])/ /;
|
|
|
|
s/_(.*)/\t($1)/;
|
2012-07-18 17:39:04 +00:00
|
|
|
}
|
|
|
|
|
2012-07-24 14:24:23 +00:00
|
|
|
my $maxw = max map {length} @ARGV;
|
2012-07-18 17:39:04 +00:00
|
|
|
|
2012-07-24 14:24:23 +00:00
|
|
|
my $cols = max 1, (($scrw + 2) / ($maxw + 2));
|
2012-07-18 17:39:04 +00:00
|
|
|
|
2012-07-24 14:24:23 +00:00
|
|
|
my @list = map {sprintf "%-${maxw}s", $_} @ARGV;
|
2012-07-18 17:39:04 +00:00
|
|
|
|
2012-07-24 14:24:23 +00:00
|
|
|
my $rows = (@list + $cols - 1) / $cols;
|
2012-07-18 17:39:04 +00:00
|
|
|
|
2012-07-24 14:24:23 +00:00
|
|
|
my @rowlist;
|
|
|
|
for my $i (0 .. $#list) {
|
|
|
|
push @{$rowlist[$i % $rows]}, $list[$i];
|
2012-07-18 17:39:04 +00:00
|
|
|
}
|
|
|
|
|
2012-07-24 14:24:23 +00:00
|
|
|
say join ' ', @$_ for @rowlist;
|