Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
strings_search
#!/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
You can’t perform that action at this time.