in reply to Assigning REGEX Match to a separate variable?
... searches a string for a pattern match, and in scalar context returns true if it succeeds...So, just use
...
Matching in list context
If the "/g" option is not used, "m//" in list context returns a list consisting of the subexpressions matched by the parentheses in the pattern, i.e., ($1, $2, $3...). (Note that here $1 etc. are also set, and that this differs from Perl 4's behavior.) When there are no parentheses in the pattern, the return value is the list "(1)" for success.
...
The "/g" modifier ... In list context, it returns a list of the substrings matched by any capturing parentheses in the regular expression. If there are no parentheses, it returns a list of all the matched strings, as if there were parentheses around the whole pattern.
my ($changeType) = $reportData[$x] =~ /\>([A-z]+)\</;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Assigning REGEX Match to a separate variable?
by mmartin (Monk) on Apr 02, 2012 at 16:54 UTC |