in reply to Re^3: Speeding up named capture buffer access
in thread Speeding up named capture buffer access
I can't do that for the exact reason that I want to use named capture buffers. The regular expression is very complicated. It's basically of the form:
$re = qr/($re1|$re2|...|$reN)/;
where each of the pieces may match a valid time. But some may match a partial time (perhaps only hours and minutes), some may match a 24-hour time and others may include an AM/PM string, some may include timezone information, and because there are so many ways to express times, some of them may even have the order of the fields changed, so I wouldn't want to depend on the order of the matches always being ($h,$mn,$s).
So, using numbered matches, I could do something like:
foreach $re ($re1,$re2,...) {
($h,$mn,$s) = $string =~ $re;
last if ($h,$mn,$s)
}
except that that won't work because I'm relying on the order of matches (and assuming that there will always be an $h match, etc).
With named capture buffers, I can do this so elegantly. I define each regexp, name the capture buffers (in whatever order they come in) and the named buffer will contain all the ones that actually matched. Maintaining the complicated regexps in Date::Manip is about 100 times easier now!
|
|---|