diff options
-rwxr-xr-x[-rw-r--r--] | 008/ch1.pl | 0 | ||||
-rwxr-xr-x | 008/ch2.pl | 23 |
2 files changed, 23 insertions, 0 deletions
diff --git a/008/ch1.pl b/008/ch1.pl index 0327467..0327467 100644..100755 --- a/008/ch1.pl +++ b/008/ch1.pl diff --git a/008/ch2.pl b/008/ch2.pl new file mode 100755 index 0000000..d9857bf --- /dev/null +++ b/008/ch2.pl @@ -0,0 +1,23 @@ +#!/usr/bin/env perl + +use strict; +use warnings; + +use List::Util qw(max reduce); + +sub center { + # Get length of the longest string + my $maxlen = reduce { max($a, length $b) } 0, @_; + + # Add the needed spaces to the beginning of each string + return map { ' ' x (($maxlen - length) / 2) . $_ } @_; +} + +my @lines; +while (<>) { + chomp; + push @lines, $_; +} +for (center(@lines)) { + print $_, "\n"; +} |