diff options
author | Mattias Andrée <maandree@operamail.com> | 2012-07-24 16:40:58 +0200 |
---|---|---|
committer | Mattias Andrée <maandree@operamail.com> | 2012-07-24 16:40:58 +0200 |
commit | e928a02e8a4a1fa2f4d68d109e2d9080e7b0d0a6 (patch) | |
tree | 03fc4412252ce4b68f32c08c9df8a2ec59881c4c | |
parent | 39341e46e62abadd299beec0b6a2dadb5694f282 (diff) | |
download | ponysay-e928a02e8a4a1fa2f4d68d109e2d9080e7b0d0a6.tar.gz ponysay-e928a02e8a4a1fa2f4d68d109e2d9080e7b0d0a6.tar.bz2 ponysay-e928a02e8a4a1fa2f4d68d109e2d9080e7b0d0a6.zip |
Revert "Merge pull request #54 from spider-mario/master"
Error at line 29
This reverts commit 39341e46e62abadd299beec0b6a2dadb5694f282, reversing
changes made to 4e1655bc0bb213c001848d02342bcdcd60f4f110.
-rwxr-xr-x | ponysaylist.pl | 71 |
1 files changed, 51 insertions, 20 deletions
diff --git a/ponysaylist.pl b/ponysaylist.pl index 0e2db56..401d83b 100755 --- a/ponysaylist.pl +++ b/ponysaylist.pl @@ -1,4 +1,4 @@ -#!/usr/bin/env perl +#!/usr/bin/perl # ponysaylist # Prints a list of ponies in columns @@ -9,32 +9,63 @@ # Author: Mattias Andrée, maandree@kth.se -use strict; -use warnings; -use utf8; -use feature qw(say); -use integer; -use List::Util qw(max); +$first = 1; +$scrw = 1; +$maxw = 1; -my $scrw = shift @ARGV; - -for (@ARGV) { +foreach $arg (@ARGV) +{ # Format names from ponyies names - s/(?<=[a-z])(?=[A-Z])/ /; - s/_(.*)/\t($1)/; + $arg =~ s/([a-z])([A-Z])/\1 \2/; + #$arg =~ s/_(.*)/\t(\1)/; ## Incompatible with `ponysay -L` + + if ($first == 1) + { $first = 0; + $scrw = $arg; + } + else + { $w = length $arg; + $maxw = $w if ($w > $maxw); + } } -my $maxw = max map {length} @ARGV; +$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; + } +} -my $cols = max 1, (($scrw + 2) / ($maxw + 2)); -my @list = map {sprintf "%-${maxw}s", $_} @ARGV; +$rows = int (($items + $cols - 1) / $cols); +$i = 0; +@rowlist = (); -my $rows = (@list + $cols - 1) / $cols; +while ($i < $items) +{ $row = 0; + while (($row < $rows) and ($i < $items)) + { + $rowlist[$row] .= " " unless ($i < $rows); + $rowlist[$row] .= $list[$i]; + $row += 1; + $i += 1; +} } -my @rowlist; -for my $i (0 .. $#list) { - push @{$rowlist[$i % $rows]}, $list[$i]; +foreach $row (@rowlist) +{ + print $row."\n"; } -say join ' ', @$_ for @rowlist; |