<?xml version="1.0" encoding="windows-1252"?>
<node id="79450" title="Re: Golf (Inspired): Repeated Phrases" created="2001-05-10 16:05:57" updated="2005-07-19 14:08:39">
<type id="11">
note</type>
<author id="5348">
Corion</author>
<data>
<field name="doctext">
&lt;p&gt;My solution is not really a competitor, since I'm not that
familiar with Perl Golf customs, so bear with me.&lt;/p&gt;
&lt;code&gt;
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
};
&lt;/code&gt;
&lt;p&gt;Why I'm posting this at all is, that a previous version
 exhibited unanticipated (by me, that is) behaviour :
&lt;/p&gt;
&lt;code&gt;
  # Previous version :
  my $l = " $a! $b";
  while($l =~ s/(.*)(( \w+){$m,$n} )(.*!.*\2.*)/ $1 =$4/) {
    push @r, $2;
  };
  @r
&lt;/code&gt;
&lt;p&gt; That version only found the &lt;tt&gt;$m&lt;/tt&gt;-word
matches, because the greedy &lt;tt&gt;(.*)&lt;/tt&gt; 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 ... ).&lt;/p&gt;</field>
<field name="root_node">
79364</field>
<field name="parent_node">
79364</field>
</data>
</node>
