aboutsummaryrefslogtreecommitdiff
path: root/challenge-045/ryan-thompson/perl/ch-1.pl
blob: 695f96340b9466bb0c579057afda901fe4466452 (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
#!/usr/bin/env perl
#
# ch-1.pl - Square secret code
#
# Ryan Thompson <rjt@cpan.org>

use 5.010;
use warnings;
use strict;

use constant COLUMNS => 8;

my $plaintext = 'The quick brown fox jumps over the lazy dog';

say encode($ARGV[0] // $plaintext);

sub encode {
    local $_ = lc shift;
    s/\s//g;
    my ($i, @s);

    map { $s[$i++ % COLUMNS] .= $_ } split '';

    join ' ', @s;
}