Skip to content

Instantly share code, notes, and snippets.

@tomcha
Created March 16, 2019 16:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomcha/26e5d609972add00600a2df64a086758 to your computer and use it in GitHub Desktop.
Save tomcha/26e5d609972add00600a2df64a086758 to your computer and use it in GitHub Desktop.
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