John W. Krahn wrote:
Richard Lee wrote:
While reading 'mastering perl', I run into @- and @+ for the first time.

perldoc perlvar


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 length of the first match is 2. 8 - 7 = 1. If $+[1] had the value 8 then the first match would only have a length of 1.

Look at the @LAST_MATCH_START entry in:

perldoc perlvar


Also read the entries for $<digits>, $MATCH, $PREMATCH, $POSTMATCH, $LAST_PAREN_MATCH, $^N, @LAST_MATCH_END and $LAST_REGEXP_CODE_RESULT.

And of course the regular expression documentation:

perldoc perlrequick
perldoc perlretut
perldoc perlre
perldoc perlop



John


Thanks John,

According to the doc,

since $1 is  substr($var, $-[1], $+[1] - $-[1] )

and hi matches 7 and 8th elements of the variable and length has to be 2, so
substr($var, 7, 2), but I still don't understand because if formula was applied directly, it still would be, substr($var, 7, (8-7)) which would come out to substr($var, 7, 1). so, how I am reading it is then, $+[1] is not a value that I read off the variable but something perl assigns it to it the way it see fit?(in order to match the first match $1) and since lenght of the match is 2, $-[1] is fixed(where the match starts) but $+[1] tries to match the length?

@+ definition does mentions $+[1] is hte offset past where $1 ends.


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


Reply via email to