in reply to Re: Finding the right $<*digit*> capture variable
in thread Finding the right $<*digit*> capture variable
Beware that this approach cannot discover the last defined match variable, since there may be gaps in the list: for example after "b" =~ /(a)?(b)/, $1 will not be defined even though $2 is.
Since there is no useful absolute limit on the highest numbered match variable you might need to check for, I wondered whether walking the symbol table might give a clue, but no such luck - the symbol table entries for *1 etc are created only if they are explicitly referenced in the code:
prints "0, 4"."abcde" =~ /(.)(.)(.)(.)(.)/; my $var = $4; print join ', ', grep !/\D/, keys %::;
Accordingly, I think it is not possible in pure perl to discover the highest numbered defined match variable using any perl before v5.6.0 (when @+ and friends were first introduced).
Hugo
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re: Finding the right $<*digit*> capture variable
by diotalevi (Canon) on Apr 17, 2003 at 13:48 UTC | |
by hv (Prior) on Apr 17, 2003 at 14:29 UTC |