OK, first:

$job{ra}=~/^(.*)\d\d/

does two things: returns true if $job{ra} contains two digits, and assigns
the portion of the string BEFORE the two digits to $1.

Second: The ? is not part of the regex. Syntax x?y:z evaluates to y if x
is true, or to z if x is false, basically an inline if-then-else.
So equivalent to:

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

length $1, of course, is the offset to the two digits.

On 11 Sep 2001, Rupert Heesom wrote:

> Date: 11 Sep 2001 14:20:57 -0400
> From: Rupert Heesom <[EMAIL PROTECTED]>
> To: [EMAIL PROTECTED]
> Cc: Beginners Perl <[EMAIL PROTECTED]>
> Subject: Re: Problems using REGEXP
>
> On 10 Sep 2001 10:15:38 -0700, [EMAIL PROTECTED] wrote:
> > For position, try:
> >
> > $p=($job{ra}=~/^(.*)\d\d/?length $1:-1);
> >
> > $p is 0-based index of '\d\d', or -1 if none.
>
> Wow, I can hardly follow the syntax above.  It's very compact.
>
> Could you perhaps break it down so that I can understand what  you've
> put in it.  Particularly the REGEXP of '/^(.*)\d\d/', the next part
> "?length" and the "$1:-1".
>
> Actually having looked at one of my Perl books, I can see that /^(.*)/
> means "match any character from the beginning of the string".
>
> //? I can't quite find the meaning of.  //*? means match 0 or more
> times, //+? means match 1 or more times, //?? means match 0 or 1 time.
>
> However, once the regexp is matched, can I compare each of the 2 digit
> numbers found with a reference number?
>
>


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

Reply via email to