2012-07-24 17:13:01 +02:00
|
|
|
#!/usr/bin/env perl
|
2012-07-18 19:39:04 +02: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-28 14:24:37 +02:00
|
|
|
# spider-mario
|
2012-07-18 19:39:04 +02:00
|
|
|
|
|
|
|
|
2012-07-24 17:13:01 +02:00
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
use utf8;
|
|
|
|
use feature qw(say);
|
|
|
|
use integer;
|
|
|
|
use List::Util qw(max);
|
2012-07-18 19:39:04 +02:00
|
|
|
|
2012-07-28 12:20:46 +02:00
|
|
|
my $scrw = shift @ARGV // 1;
|
2012-07-24 17:13:01 +02:00
|
|
|
|
2012-07-28 14:24:37 +02:00
|
|
|
#for (@ARGV) {
|
|
|
|
# # Format names from pony names
|
|
|
|
# s/(?<=[a-z])(?=[A-Z])/ /;
|
|
|
|
# s/_(.*)/\t($1)/;
|
|
|
|
#}
|
2012-07-18 19:39:04 +02:00
|
|
|
|
2012-07-28 12:20:46 +02:00
|
|
|
my $maxw = max 1, map {length} @ARGV;
|
2012-07-18 19:39:04 +02:00
|
|
|
|
2012-07-24 17:13:01 +02:00
|
|
|
my $cols = max 1, (($scrw + 2) / ($maxw + 2));
|
2012-07-18 19:39:04 +02:00
|
|
|
|
2012-07-24 17:13:01 +02:00
|
|
|
my @list = map {sprintf "%-${maxw}s", $_} @ARGV;
|
2012-07-18 19:39:04 +02:00
|
|
|
|
2012-07-24 17:13:01 +02:00
|
|
|
my $rows = (@list + $cols - 1) / $cols;
|
2012-07-18 19:39:04 +02:00
|
|
|
|
2012-07-24 17:13:01 +02:00
|
|
|
my @rowlist;
|
|
|
|
for my $i (0 .. $#list) {
|
|
|
|
push @{$rowlist[$i % $rows]}, $list[$i];
|
2012-07-18 19:39:04 +02:00
|
|
|
}
|
|
|
|
|
2012-07-24 17:13:01 +02:00
|
|
|
say join ' ', @$_ for @rowlist;
|