aboutsummaryrefslogtreecommitdiff
path: root/ponysaylist.pl
blob: 0e2db565c0478e7fe89ddd81547750a0e13c8542 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/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


use strict;
use warnings;
use utf8;
use feature qw(say);
use integer;
use List::Util qw(max);

my $scrw = shift @ARGV;

for (@ARGV) {
	# Format names from ponyies names
	s/(?<=[a-z])(?=[A-Z])/ /;
	s/_(.*)/\t($1)/;
}

my $maxw = max 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;