Help ME! --> Alas - Backreferences are Lexically scoped

From: Sumanth Sharma (sumanth_at_relq.com)
Date: 04/29/04


To: beginners@perl.org
Date: Thu, 29 Apr 2004 10:20:41 +0530

Hi,
    Read with Patience.

    Backreferences( $1, $2 ...) are lexically scoped,

   which means

   in a match like m/(<REGEX1>)(<REGEX2>) etc ..../

   Suppose REGEX1 does not match, then $1 remains undefined, and if REGEX2,
3 ... do match then $2, $3 will respectively hold the matches in parentheses
2, 3 etc.

  My problem is
   say $some_var = "ababababababab"; ##here ab occurs 7 times

   if I say

  @get_match_list = ( $some_var =~ m/(ab){5,14}/g );
  ## i.e get a least 5 matches and at most 14

  @get_match_list will contain only one val i.e "ab",
  that's b'coz $1 is lexically scoped to the first( the only ) parentheses
in the reg-exp.

 So, $1 is overwritten on each match.

 IN SUCH A SCENARIO, IS IT POSSIBLE TO GET ALL THE MATCHES

THANKS IN ADVANCE,
Sumanth Sharma