From 40164221fbae896ba14715fa0c01cbb56a426105 Mon Sep 17 00:00:00 2001 From: Elis Axelsson Date: Sat, 21 Jul 2012 09:36:33 +0200 Subject: Updated perl-script to format the ponies names --- ponysaylist.pl | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'ponysaylist.pl') diff --git a/ponysaylist.pl b/ponysaylist.pl index 7a09376..72c0a92 100755 --- a/ponysaylist.pl +++ b/ponysaylist.pl @@ -15,6 +15,10 @@ $maxw = 1; foreach $arg (@ARGV) { + # Format names from ponyies names + $arg =~ s/([a-z])([A-Z])/\1 \2/; + $arg =~ s/_(.*)/\t(\1)/; + if ($first == 1) { $first = 0; $scrw = $arg; -- cgit From c374d57fd365833807c2e191178848d76828e859 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Tue, 24 Jul 2012 16:16:59 +0200 Subject: /tmp/ponythink instead of /tmp/.ponythink --- ponysaylist.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ponysaylist.pl') diff --git a/ponysaylist.pl b/ponysaylist.pl index 72c0a92..401d83b 100755 --- a/ponysaylist.pl +++ b/ponysaylist.pl @@ -17,7 +17,7 @@ foreach $arg (@ARGV) { # Format names from ponyies names $arg =~ s/([a-z])([A-Z])/\1 \2/; - $arg =~ s/_(.*)/\t(\1)/; + #$arg =~ s/_(.*)/\t(\1)/; ## Incompatible with `ponysay -L` if ($first == 1) { $first = 0; -- cgit From b51d03f6263d3ef674f01be9c01a5b6539e61caf Mon Sep 17 00:00:00 2001 From: spider-mario Date: Tue, 24 Jul 2012 16:24:23 +0200 Subject: Rewrote ponysaylist.pl. --- ponysaylist.pl | 71 +++++++++++++++++----------------------------------------- 1 file changed, 20 insertions(+), 51 deletions(-) (limited to 'ponysaylist.pl') diff --git a/ponysaylist.pl b/ponysaylist.pl index 401d83b..0e2db56 100755 --- a/ponysaylist.pl +++ b/ponysaylist.pl @@ -1,4 +1,4 @@ -#!/usr/bin/perl +#!/usr/bin/env perl # ponysaylist # Prints a list of ponies in columns @@ -9,63 +9,32 @@ # Author: Mattias Andrée, maandree@kth.se -$first = 1; -$scrw = 1; -$maxw = 1; +use strict; +use warnings; +use utf8; +use feature qw(say); +use integer; +use List::Util qw(max); -foreach $arg (@ARGV) -{ +my $scrw = shift @ARGV; + +for (@ARGV) { # Format names from ponyies names - $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); - } + s/(?<=[a-z])(?=[A-Z])/ /; + s/_(.*)/\t($1)/; } -$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 $maxw = max map {length} @ARGV; +my $cols = max 1, (($scrw + 2) / ($maxw + 2)); -$rows = int (($items + $cols - 1) / $cols); -$i = 0; -@rowlist = (); +my @list = map {sprintf "%-${maxw}s", $_} @ARGV; -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 $rows = (@list + $cols - 1) / $cols; -foreach $row (@rowlist) -{ - print $row."\n"; +my @rowlist; +for my $i (0 .. $#list) { + push @{$rowlist[$i % $rows]}, $list[$i]; } +say join ' ', @$_ for @rowlist; -- cgit From e928a02e8a4a1fa2f4d68d109e2d9080e7b0d0a6 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Tue, 24 Jul 2012 16:40:58 +0200 Subject: Revert "Merge pull request #54 from spider-mario/master" Error at line 29 This reverts commit 39341e46e62abadd299beec0b6a2dadb5694f282, reversing changes made to 4e1655bc0bb213c001848d02342bcdcd60f4f110. --- ponysaylist.pl | 71 +++++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 51 insertions(+), 20 deletions(-) (limited to 'ponysaylist.pl') 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; -- cgit