Last active
December 15, 2015 05:48
-
-
Save sng2c/5211212 to your computer and use it in GitHub Desktop.
perl에서 index() 와 같이 작동하지만 인자는 배열인 거. https://gist.github.com/am0c/dc65b37eca606e74e760 에 offset 추가
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
sub index_array { | |
my ($array, $key, $offset) = @_; | |
my $i = 0; | |
for my $i ($offset .. $#$array) { | |
my $is_eql = 1; | |
for my $j (0 .. $#$key) { | |
last if $i + $j > $#$array; | |
if ($key->[$j] ne $array->[$i + $j]) { | |
$is_eql = 0; | |
last; | |
} | |
} | |
return $i if $is_eql; | |
} | |
return -1; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment