Advertisement
Guest User

Untitled

a guest
Mar 21st, 2019
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. #!/usr/bin/env perl
  2.  
  3. use strict;
  4. use warnings;
  5. use feature 'say';
  6.  
  7. use DDP { deparse => 1 };
  8.  
  9. my $strings = 'ssddperffgggperlasdf';
  10. my $target = 'perl';
  11. my @strings = split(//, $strings);
  12. my @target = split(//, $target);
  13.  
  14. my $count = scalar @strings - scalar @target;
  15.  
  16. for my $i (0..$count){
  17. if ($strings[$i] eq $target[0]){
  18. for my $j (1..((scalar @target) - 1)){
  19. last if $strings[$i + $j] ne $target[$j];
  20. if ($j == ((scalar @target) - 1)){
  21. say "match index:$i";
  22. exit;
  23. }
  24. }
  25. }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement