Help ME! --> Alas - Backreferences are Lexically scoped
From: Sumanth Sharma (sumanth_at_relq.com)
Date: 04/29/04
- Next message: Sumanth Sharma: "Re: How to change @INC"
- Previous message: Jeff Westman: "Re: confused - if function"
- Next in thread: Damon Allen Davison: "Re: Help ME! --> Alas - Backreferences are Lexically scoped"
- Reply: Damon Allen Davison: "Re: Help ME! --> Alas - Backreferences are Lexically scoped"
- Maybe reply: Damon Allen Davison: "Re: Help ME! --> Alas - Backreferences are Lexically scoped"
- Reply: John W. Krahn: "Re: Help ME! --> Alas - Backreferences are Lexically scoped"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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
- Next message: Sumanth Sharma: "Re: How to change @INC"
- Previous message: Jeff Westman: "Re: confused - if function"
- Next in thread: Damon Allen Davison: "Re: Help ME! --> Alas - Backreferences are Lexically scoped"
- Reply: Damon Allen Davison: "Re: Help ME! --> Alas - Backreferences are Lexically scoped"
- Maybe reply: Damon Allen Davison: "Re: Help ME! --> Alas - Backreferences are Lexically scoped"
- Reply: John W. Krahn: "Re: Help ME! --> Alas - Backreferences are Lexically scoped"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]