On 11/14/05, Patrick R. Michaud <[EMAIL PROTECTED]> wrote: > On Mon, Nov 14, 2005 at 06:59:51PM -0800, jerry gay wrote: > > it seems that in keyed string access to the match object, the result > > is returned directly as a string. in keyed integer access to the match > > object, an intermediate pmc must be used. although the workaround is > > simple, the lack of symmetry seems odd. is this due to PIR > > restrictions, or to PGE implementation? > > Well, I suppose it can be argued either way. First, note that > PGE::Match is a subclass of Hash, so one has available all of the > (non-integer) keyed methods by default. The PGE::Match object > then overloads some (but currently not all) of the *_keyed_int > methods to be able to provide access to the array component of the > Match object. > > Thus, while PGE::Match currently defines a C<__get_pmc_keyed_int> > method, it's doesn't yet define a C<__get_string_keyed_int> method. > So, a statement like > > .local string res > .local pmc match > res = match[0] > > is defaulting to using the inherited op from the Hash class, and > since there's not an entry at the 0 key in the hash (as opposed to > the array) you get the null PMC. > it seems to me it could inherit from Array as well, but it may not be a precise fit.
> I guess I should go ahead and provide methods in the match objects > for the other *_keyed_int operations, if only to avoid this sort of > confusion and the need to store things to an intermediate pmc. > this is probably the better way to go, and seems easy enough to implement (and test.) :) i'll take a stab at it, if you don't mind. > Another possibility may be to simply use the hash for all captures, > including the "array" captures, thus removing the numbers from > being valid keys. Something I read in S05 leads me to believe > that $/<1> and $/[1] are actually the same, in which case we might > not need the separate "array component" and *_keyed_int methods > for Match objects. > if my read of S05 is correct, i believe $<1> (and $1) equates to $/[0]. of course, you may have a newer copy than i do. ;) i still have some tests to write for match return values, i'll try to get some tests in for the above based on a close reading of S05. ~jerry