Skip to content

Instantly share code, notes, and snippets.

@sng2c
Last active December 15, 2015 05:48
Show Gist options
  • Save sng2c/5211212 to your computer and use it in GitHub Desktop.
Save sng2c/5211212 to your computer and use it in GitHub Desktop.
perl에서 index() 와 같이 작동하지만 인자는 배열인 거. https://gist.github.com/am0c/dc65b37eca606e74e760 에 offset 추가
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