In article <[EMAIL PROTECTED]>, Richard Lee
<[EMAIL PROTECTED]> wrote:

> While reading 'mastering perl', I run into @- and @+ for the first time.
> Trying to understand what's going on, I ran the code from the book, but
> 
> $-[1] and $+[1] shoudln't match only the first match? (in this case,
> shoudln't it be, 7 to 8 ?, instead of 7 to 9 ?)

The @+ array holds the current offsets for the match for the part that
just matched. If the thing in $1 was at positions 7 and 8, the next
place where the match starts is at position 9. That's what's in @+.
This
makes it pretty easy to do math. As you see in the substr, you only
need to do a single subtraction. If @+ went the other way, you'd also
have to add 1 to the difference.

It could have been some other way, but it's not. This is one of those
things where you just have to know what that variable has, not
understand why it's one way and not the other. :)

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


Reply via email to