Created
March 16, 2019 16:48
-
-
Save tomcha/26e5d609972add00600a2df64a086758 to your computer and use it in GitHub Desktop.
strings_search
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment