Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use List::MoreUtils 'firstidx';
- use List::MoreUtils 'firstidx';
- my @letters = a..z;
- sub get_next_index {
- my $index = shift;
- my $max = scalar(@letters);
- my $i = 0;
- while($i != 2) {
- $i++;
- if ($index+2 > $max) {
- $index = -1;
- }
- $index++;
- }
- return $index;
- }
- sub translate {
- my $str = shift;
- my @string = split undef, $str;
- my @final_string;
- for my $char (@string) {
- if ($char =~ /\s+/) {
- push @final_string, ' ';
- next;
- }
- my $index = -1;
- $index = firstidx { $_ eq $char } @letters;
- if ($index) {
- push @final_string,
- $letters[get_next_index($index)];
- }
- }
- return join(undef, @final_string);
- }
- my $get_string = translate("fcjjm umpjb bgb wms ilmu rfc qsl gq wcjjmu");
- print "$get_string\n";
Add Comment
Please, Sign In to add comment