Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env perl
- use strict;
- use warnings;
- use feature 'say';
- use DDP { deparse => 1 };
- my $strings = 'ssddperffgggperlasdf';
- my $target = 'perl';
- my @strings = split(//, $strings);
- my @target = split(//, $target);
- my $count = scalar @strings - scalar @target;
- for my $i (0..$count){
- if ($strings[$i] eq $target[0]){
- for my $j (1..((scalar @target) - 1)){
- last if $strings[$i + $j] ne $target[$j];
- if ($j == ((scalar @target) - 1)){
- say "match index:$i";
- exit;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement