> $field =~ /^(?:([1-9]\d?)\.){2}\1$/;

That won't work either.  When you say ([1-9]\d?) you're telling it
"(If there is a match) capture the stuff in parentheses and store it."
 When you say "\1" you're telling the script "you know that first
batch of stuff you captured?  Well I want that here."  But it's not
the pattern, it's the literal substring of the match.

Let's simplify it a little bit and consider this example:

10.15 =~ /^([1-9]\d?)\.\1$/;

In this case it would not match.  It works like this:

1.  [1-9]\d? matches 10.
2.  () stores that value "10" as \1 (or actually as $1, but within the
pattern you dereference it with \1).  Note that it doesn't store the
pattern "[1-9]\d?", but the actual substring "10".  So at this point,
the \1 becomes "10" and looks like this:

/^[1-9]\d?\.10$/

Obviously 15 !~ 10, so there is no match.

You would use that if you wanted to find things like 1.1 or 10.10.

With your expression:
10.15.20 =~ /^(?:([1-9]\d?)\.){2}\1$/;

1.  [1-9]\d? - Matches 10.
2.  () - Stores "10" as $1.  
3.  Pattern now looks like /^(?:([1-9]\d?)\.){2}10$/
4.  {2} - Requires a second match of (?:([1-9]\d?)\.).
5.  [1-9]\d? - Matches 15.  
6.  () - Stores "15" as $1 (overwriting the previous value).  (I may
be mistaken on what exactly happens here, but this is effectively the
case.  If so, someone more knowledgable will hopefully correct me.)
7.  Pattern now looks like /^(?:([1-9]\d?)\.){2}15$/
8.  20 !~ 15, so pattern does not match.

So your expression will match 10.10.10 or even 10.15.15, but it won't
match 10.15.20.

HTH

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to