On Wed, Apr 27, 2005 at 08:46:53AM -0400, Joshua Gatcomb wrote: > The problem is that in the regex version I use capturing parens to > identify the character matched. For the purposes of the problem I > don't need to rely on the first character matched I just need to know > 1. > > Without doing a lot of research into junctions, I thought the > following would work: > > my $matches = any( @x_chars ) eq any( @y_chars ); > my $match = $matches.pick;
Perhaps the easiest way to explain the difficulty here is to note that executing a relational op (i.e. returning a boolean) value on a junction argument returns a junction of boolean values. So, the C<eq> expression above doesn't contain the intersection of chars that match, it's just a junction of the (boolean) values returned by &infix:<eq> on each pair of arguments from @x_chars and @y_chars. Actually, since there's two junction arguments, the result will be an C<any> junction of C<any> junctions. > The worst that could happen is that I find out > there isn't a way to get a what matched from an any() eq any() > comparison. Not using the standard &infix:<eq>, no. But I suppose one could get close to what you're wanting with something like: sub &infix:<myeq>(Str $a, Str $b) { return ($a eq $b) ? $a : ''; } and then my $matches = any( @x_chars ) myeq any( @y_chars ); my $match = $matches.pick; although since $match is any( any( ... ), any( ... ), any( ... ) ) I'm not sure if C<.pick> would end up "picking" a junction as opposed to one of the inner values, or if it could "pick" one of the empty string values. Anyway, hope this helps clear up why the original wasn't working. Pm