in reply to Re^5: How to know that a regexp matched, and get its capture groups?
in thread How to know that a regexp matched, and get its capture groups?
$#caps = $#- - 1;
As I linked to in my update here, there is a subtle but important distinction between $#- and $#+. You can see this in action if you add e.g. qr/A(X)?/ as one of the test regexes, with $#+ - 1 the resulting @caps will be (undef) instead of being empty, thus correctly reflecting the number of capture groups present in the regex. Yet another solution might be $cb->($#+ ? @caps : ()).
|
---|