Mike Liss wrote:
> Hello,
>
> Is there an easy way to get the location of a specific instance of a
> character
> in an array?
>
> for example:
>
> $MyArray = "This is the test";
>
> I would like to know the index of the first occurence of the letter
> "h" ( 1 )
Hi Mike
I thought you may be interested in an alternative.
$str =~ m/\Q$substr/g;
print pos($str) - length($substr), "\n";
which is similar to 'print index $str, $substr, "\n"' but has the
advantage that it works on a regular expression. It can also be put into
a loop without troubling to use index's third 'position' parameter.
while ( $str =~ m/\Q$substr/g )
{
print pos($str) - length($substr), "\n";
}
Cheers,
Rob
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]