aboutsummaryrefslogtreecommitdiff
path: root/challenge-097/lance-wicks/perl/ch-1.pl
blob: b12b5ff98d7ac4f16d9072ee58cc368ea9a87fc8 (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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
use strict;
use warnings;

use lib './lib';
use Caesar;

use Getopt::Long;

my ($string,$n,$decode);
GetOptions(
    'string=s' => \$string,
    'n=i'      => \$n,
    'd'        => \$decode,
);

unless ($string && $n) {
    die <<"MESSAGE";

MISSING PARAMS

You need to provide:
 -s "the string to encode goes here"
 -n 3


eg perl ch-1.pl -s "foo bar" -n 3

Which rotates "foo bar" by three characters, returning:
CLL YXO

By default the script will encode, add the -d param to decode.


MESSAGE
}


my $caesar = Caesar->new;

my $text;
if ($decode) {
    $text = $caesar->decode(
        string => $string,
        n      => $n,
    );
} else {
    $text = $caesar->encode(
        string => $string,
        n      => $n,
    );

}
print $text;
print "\n";