in reply to variables in global match in regex
The /g modifier on the regexp, in scalar context, returns the next (in your case, the first) match. If you iterated over the regexp again, it would return the second match, etc.
Thus, this sort of construct might be what you're looking for:
while ( $mystring =~ /(regexp)/g ) { do_something_with($1); }
Alternatively, evaluating the regexp with a /g modifier in list context will return a list of all matches without explicitly looping.
if ( my( @matches ) = $mystring =~ m/(regexp)/g ) { do_something_with( @matches ); }
Hope this helps. ...see perlrequick for a brief description of using /g in list and scalar context while capturing matches.
Also, you could slurp the file instead of joining all the lines together by setting the special variable $/ to undef. Then you might use the /s modifier on your regexp in addition to the /g modifier if your regexp uses the . (dot) metacharacter and you want it to accept \n newlines the same as any other character. Just a thought. See perlvar for a description of $/.
Dave
|
|---|