Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

Hello ISAI student,

To expand a little on tobyink’s answer:

My reaction to your question is: Take a step back, and look at the wider picture. Modularity is an excellent goal, but why? Because a script composed of self-contained modules, loosely coupled together, is easier to debug/maintain/enhance than a monolithic script “riddled with global variables” (to use your words). But conversion of global variables into lexical variables is a means to this end, not a goal in itself. The aim is to produce modularity and loose coupling: global variables shared across a script entail tight coupling.

Now, I could be wrong, but it seems to me that your proposed solution is to retain global variables in all but name — to have the same variables shared across the whole script, but to make these variables lexical via a monster hash which is passed by reference to all the subroutines. The likely result is that you will end up with the same tight coupling as before, but implemented in a more complicated syntax which is even harder to debug/maintain/enhance than the original.

The bottom line is this: If you want the benefits of modularity, you must have loose coupling. And to achieve loose coupling, you must identify which variables need to be shared between modules, and refrain from sharing any which do not. For this, there is, alas!, no easy fix — you have to re-design and re-factor before you can re-code. And the measure of success is this: the end result must be simpler and clearer than the original.

I know this advice is not what you were hoping to hear, but I think it’s good advice all the same. I hope it helps,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

In reply to Re: using eval or equivalent to automatically generate my statements by Athanasius
in thread using eval or equivalent to automatically generate my statements by ISAI student

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, 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
  • 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.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others perusing the Monastery: (6)
    As of 2018-05-22 10:43 GMT
    Find Nodes?
      Voting Booth?