L
Larry
I'm using a /g regex in a while loop to capture parenthesized matches
to meaningful variable names like this:
while (/ (...) ... (...) ... (...)/g) {
my ($foo, $bar, $baz) = ($1, $2, $3);
...
}
The ($1, $2, $3) part seems inelegant ... is there a more elegant way?
BTW, don't suggest:
while (my ($foo, $bar, $baz) = / (...) ... (...) ... (...)/g) {
...
}
That will cause the regex to evaluate in a list context, which changes
the behavior of /g to parse all of $_ at once, only returning the
first match and throwing away the rest.
to meaningful variable names like this:
while (/ (...) ... (...) ... (...)/g) {
my ($foo, $bar, $baz) = ($1, $2, $3);
...
}
The ($1, $2, $3) part seems inelegant ... is there a more elegant way?
BTW, don't suggest:
while (my ($foo, $bar, $baz) = / (...) ... (...) ... (...)/g) {
...
}
That will cause the regex to evaluate in a list context, which changes
the behavior of /g to parse all of $_ at once, only returning the
first match and throwing away the rest.