Jonathan Scott Duff wrote: > Question #3: > > Related to question #2, if I didn't use hypotheticals, how would I > access the Nth match of a repitition? For instance, in E5, there's an > example that looks like this: > > rule file { ^ @adonises := <hunk>* $ } > > If I didn't have the hypothetical @adonises, how would I retrieve the > 3rd hunk matched? Would I need to write it like so: > > rule file { ^ <hunks> $ } > rule hunks :e { (<hunk>) } > > and then access it with $0{file}{hunks}[2] ?
For a while worries about this have been brewing in my mind. [worry #1] The hypothetical 'variables' we bind to aren't really variables but keys to a hash. Thus they shouldn't have sigils in their names at all. Ok, that may give us problems with giving rules context, but maybe we could simplify that, such that rules always got scalar context to work in (that's pretty close to the truth anyhow since their results are being stored in a hash - for some definition of 'truth'). Then maybe we could differentiate between building a match object and capturing data into variables that are defined in a higher scope. So /^ <hunks> $ / (or alternately (the binding just changes the name of the key in the match object)) /^ myhunk := <hunks> $ / and /^ $hunk := <hunks> $ / would do different things, since the first only builds a match object, and the second only binds $hunk. [worry #2] Since $0 has only a rather vague relation to $1..$n, maybe its name isn't that relevant. Especially since we'll be indexing into it all the time. Maybe $MATCH, $RESULT, $RX .... (those names aren't convincing me either, sorry). If nothing else, this would at least get rid of "one more cryptically names variable". David -- www.panmedia.dk - Excellent Perl consulting for Denmark, Scandinavia, the World