My solution is not really a competitor, since I'm not that
familiar with Perl Golf customs, so bear with me.
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
};
Why I'm posting this at all is, that a previous version
exhibited unanticipated (by me, that is) behaviour :
# Previous version :
my $l = " $a! $b";
while($l =~ s/(.*)(( \w+){$m,$n} )(.*!.*\2.*)/ $1 =$4/) {
push @r, $2;
};
@r
That version only found the $m-word
matches, because the greedy (.*) 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 ... ).
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
Outside of code tags, you may need to use entities for some characters:
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.
|
|