Guest User

Untitled

a guest
Dec 15th, 2018
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 0.90 KB | None | 0 0
  1. use List::MoreUtils 'firstidx';
  2. use List::MoreUtils 'firstidx';
  3. my @letters = a..z;
  4.  
  5. sub get_next_index {
  6.     my $index = shift;
  7.     my $max   = scalar(@letters);
  8.  
  9.     my $i = 0;
  10.     while($i != 2) {
  11.         $i++;
  12.         if ($index+2 > $max) {
  13.             $index = -1;
  14.         }
  15.         $index++;
  16.     }
  17.  
  18.     return $index;
  19. }
  20.  
  21. sub translate {
  22.     my $str = shift;
  23.     my @string = split undef, $str;
  24.     my @final_string;
  25.     for my $char (@string) {
  26.         if ($char =~ /\s+/) {
  27.             push @final_string, ' ';
  28.             next;
  29.         }
  30.         my $index = -1;
  31.         $index = firstidx { $_ eq $char } @letters;
  32.         if ($index) {
  33.             push @final_string,
  34.                 $letters[get_next_index($index)];
  35.         }
  36.     }
  37.  
  38.     return join(undef, @final_string);
  39. }
  40.  
  41. my $get_string = translate("fcjjm umpjb bgb wms ilmu rfc qsl gq wcjjmu");
  42. print "$get_string\n";
Add Comment
Please, Sign In to add comment