This actually uses index, so it should run faster than regex based versions. Benchmarking is left as an exercise for the more interested. :)
sub index_a { my( $txt, $search ) = @_; my @ret; my $ind = 0; my $cur = 0; while( ($cur = index( $txt, $search, $ind )) != -1 ) { push @ret, $cur; $ind = $cur + 1; } return @ret; }
In reply to Bones! Take a reading . . .
by Fletch
in thread Trying to get index functionality in array context
by guha
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |