I think rafl's reasoning for suggesting OO was that the general operations were similar, but there were slight variations, depending on the situation. That's a situation where PBP says using OO would be appropriate.

However, TheDamian also says to make OO a choice, not default. In a nutshell (my paraphrasing of pp. 320-321), if you have

or your data

it may benefit you to use OO. Oh, there were a couple situations in the book I left out, but that should give you the gist of it.



Also, I'd highly suggest using Perl6::Export::Attrs in writing your modules. I could never remember the syntax for writing a module, and it was a major reason why I hadn't gotten around to refactoring my code into modules, until recently. But with this, it's a lot simpler - you just specify the module with a 'use' statement, and specify :Export in your subroutine if you want it exported from the module. Example:

package myModule; use Perl6::Export::Attrs; sub DoSomething :Export { #whatever }
Of course, you can specify more, but you can look at the docs for that. This code should get you started. Oh, and you don't need to install Perl6 itself to get this, by the way; I've been using it fine on 5.8.7 and 5.6.

-- Burvil


In reply to Re: Generalizing Similar Scripts into a Module by bowei_99
in thread Generalizing Similar Scripts into a Module by deep submerge

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.