That was fun! Thanks.

#!/usr/bin/perl -l # http://perlmonks.org/?node_id=1209857 use strict; use warnings; $_ = <<END; # starting conditions John apples,cherries,pears blacksmith,fisherman,programmer Patrick apples,cherries,pears blacksmith,fisherman,programmer Edward apples,cherries,pears blacksmith,fisherman,programmer END my $prev; do { print; $prev = $_; s/^John \S*\Kpears//m; # John doesn't like pears s/^Patrick \S+ \K\S+/blacksmith/m; # Patrick is a blacksmith s/^Edward \S+ \S*\Kfisherman//m; # Edward isn't a fisherman s/\S+(?= programmer$)/cherries/m; # The programmer likes cherries s/,+\K,|\B,+|,+\B//g; # cleanup extra commas for my $col (1 .. tr/ // / tr/\n// ) # for each column { for my $one ( /^(?:\S+ ){$col}(\w+)\s/gm ) # find each single one { s/^(?:\S+ ){$col}(?:\K$one,|\S+\K,$one\b)//gm; # delete in other + rows } } } until $_ eq $prev;

Outputs:

John apples,cherries,pears blacksmith,fisherman,programmer Patrick apples,cherries,pears blacksmith,fisherman,programmer Edward apples,cherries,pears blacksmith,fisherman,programmer John apples,cherries fisherman,programmer Patrick apples,cherries,pears blacksmith Edward apples,cherries,pears programmer John apples fisherman Patrick apples,pears blacksmith Edward cherries programmer John apples fisherman Patrick pears blacksmith Edward cherries programmer

In reply to Re^2: My first cpan module - App::ForKids::LogicalPuzzleGenerator by tybalt89
in thread My first cpan module - App::ForKids::LogicalPuzzleGenerator by pawel.biernacki

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • 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, details, 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, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.