Here's the simpler problem solved by regex.

#!/usr/bin/perl use strict; use warnings; # Three friends live here. # Each likes a different fruit and has a different profession. # John doesn't like pears. # The programmer likes cherries. # Patrick is a blacksmith. # Edward isn't a fisherman. # Who likes apples? $_ = <<END; John apples,cherries,pears blacksmith,fisherman,programmer Patrick apples,cherries,pears blacksmith,fisherman,programmer Edward apples,cherries,pears blacksmith,fisherman,programmer END my @answer = /^ (\w+)\ \S*\b(\w+)\b\S*\ \S*\b(\w+)\b\S*\n # first line (\w+)\ \S*\b(\w+)\b(??{$2 eq $5})\S*\ # second line \S*\b(\w+)\b(??{$3 eq $6})\S*\n (\w+)\ # third line \S*\b(\w+)\b(??{$5 eq $8 || $2 eq $8})\S*\ \S*\b(\w+)\b(??{$6 eq $9 || $3 eq $9})\S*\n (??{ $2 eq 'pears' }) # John doesn't like pears (??{ $6 ne 'blacksmith' }) # Patrick is a blacksmith (??{ !grep $_ eq 'cherriesprogrammer', # The programmer likes cherr +ies $2.$3, $4.$5, $8.$9 }) (??{ $9 eq 'fisherman' }) # Edward isn't a fisherman /x or die "failed"; print "$1 $2 $3\n$4 $5 $6\n$7 $8 $9\n\n"; print "@answer[ map $_ - 1, grep $answer[$_] eq 'apples', 0 .. $#answer] likes apples.\n";

outputs:

John apples fisherman Patrick pears blacksmith Edward cherries programmer John likes apples.

In reply to Re^6: 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.