note
Corion
<p>My solution is not really a competitor, since I'm not that
familiar with Perl Golf customs, so bear with me.</p>
<code>
use strict;
sub f {
my ($a,$b,$m,$n) = @_;
my (@r) = ();
my $l = " $a! $b";
while($l =~ s/(.*?)(( \w+){$m,$n} )(.*!.*\2.*)/ $1 =$4/) {
push @r, $2;
};
@r
};
</code>
<p>Why I'm posting this at all is, that a previous version
exhibited unanticipated (by me, that is) behaviour :
</p>
<code>
# Previous version :
my $l = " $a! $b";
while($l =~ s/(.*)(( \w+){$m,$n} )(.*!.*\2.*)/ $1 =$4/) {
push @r, $2;
};
@r
</code>
<p> That version only found the <tt>$m</tt>-word
matches, because the greedy <tt>(.*)</tt> at the beginning
forced the RE engine to work its way backwards through
the string. As soon as I sacrificed another character,
this problem went away. I haven't given the golfing much
thought (at work, I can only think about concepts, not
byte-fiddle with REs without raising suspicions ... ).</p>
79364
79364