Well, I can't entirely agree. The code in my prior post is intended to be instructional, in the vein of "crawl before you walk; walk before you run." Given that, perhaps it should have been ("may be," if I get around to it) extensively commented.

  1. Your pseudo-code 2 doesn't match what amounts to a spec in Pseudo-code 1.
    • Pseudo-code 1 doesn't say anything about GOing to the store, so knock out lines 5 and 13
    • Pseudo-code 1 says, unambiguously, that what you want is
      1. 2% milk (no need to survey the types).
      2. the least expensive item satisfying the prior criterion. *
  2. Hence, there is no need for line 9, "compare prices to the types"
  3. Line 10 contradicts the spec; see my line 3 below.
  4. And to carry on with the absurdities, your lines 2, 11, and 12 are implicit in "buy"

* We can regard "gallon" as ambiguous, as that could mean "any combination of containers of 2% milk which aggregate to a gallon," but it might also mean that you have a specific reason for wanting the milk in a "one gallon container."

That leaves:

2: =~s/Select the type 2% where the prices is <= other prices./Buy the le +ast expensive 2% milk/;

Perhaps next time you go to the store to buy apples you should watch out for the oranges. Of course, I need to watch out too... for the absurdities to which my logic leads me.  ;-)


In reply to Re^3: Regex question by ww
in thread Regex question by Anonymous Monk

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.