Re: finding the first non digit character in a string



On 10/28/05, Bowen, Bruce <Bowenb@xxxxxxxxxxx> wrote:
> The data may look like this:
> $DD = "5000|SIHHTEXT"

> I've tried $d = index($DD, m/[^\d]/);
> $d = index($DD, /[^\d]/);
> $d = index($DD, [^\d]);

C<index> doesn't work with regexes. But you can use C<pos>

$ perl -e '$DD = "5000|SIHHTEXT"; print pos($DD) if $DD =~ /\D/g'
5

Read about this usage at C<perldoc -f pos>.

Adriano.
.



Relevant Pages