For position, try:

$p=($job{ra}=~/^(.*)\d\d/?length $1:-1);

$p is 0-based index of '\d\d', or -1 if none.

On 10 Sep 2001, Rupert Heesom wrote:

> Date: 10 Sep 2001 12:28:11 -0400
> From: Rupert Heesom <[EMAIL PROTECTED]>
> To: Beginners Perl <[EMAIL PROTECTED]>
> Subject: Problems using REGEXP
>
> Hi guys:
>
> I'm a linux enthusiast who is trying to get stuck into Perl.
>
> Currently I'm trying to put together a script which will handle text
> files.
>
> I'm having problems with one line which is trying to ascertain the
> position of ascii 2-digit numbers in a string.
>
> I've used the following line --
>
> if (($x = index($job{Ra}, /[0-90-9]/,0)) != -1)
>
> -- in which $x keeps on being assigned 0 instead of 4.
>
> The content of $job{Ra} is:  "Ra: 45k"
>
> I've fairly sure that I'm correct on the REGEXP syntax of /[0-90-9]/
> which is looking for 2 consecutive numbers in the string.  I've checked
> the REGEXP syntax with lines like --
>
> if ($job{Ra} =~ /[0-90-9]/)
>
> -- which are evaluated as True.
>
> What's going wrong in the index function above?  I should be able to use
> a REGEXP for the SUBSTR in the INDEX function shouldn't I?
>
> BTW, in case I can do this a better way, what I am trying to do is
> extract any numbers in this string.  May be 0, 1 or 2 numbers.  Then
> compare the number(s) with a "reference" number.
>
>


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to