Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Comment on

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

This is a perfect job for a combination of modules and objects. Usually when there is a lot of data that needs to be shared, it is best to encapulate all of it into a single controller class that generates all the necessary objects, manages relationships between them, launches supplemental scripts as needed and so on.

Your main launch script will then be quite simple. It just takes in command line parameters, parses them and sets up a single root object.

Global variables, in and of themselves are not bad, but a massive number of them, especially in the main namespace often signals a design problem in your code. It suggests that you haven't thought through the relationships between the global variables very carefully.

Are they constants? If so, are you cluttering up the global namespace with constant names and preventing your submodules from using those names for their own purposes? Perhaps it would be wiser to place the variables in a package and declare them as our variables. That way they still can be read by all your programs but you don't clutter up the module namespace.

If they are not constants, do they all work in concert? If so, why aren't they encapsualted in an object? If not, why is the relationship between them and why do you need so many?

There may be good reasons for making that single root object a global variable, especially if you declare the variable as an our variable in a package other than main. For example, many application API's have a single $myApp or $SOME_PACKAGE::approot variable. Any script that needs to interact with the application simply makes calls on the $myApp object.

Are you familiar with perltoot? If you are new to objects and classes in Perl, that might be a good place to start.


In reply to Re: Share data among different packages by ELISHEVA
in thread Share data among different packages by nagalenoj

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!
  • 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
  • Outside of code tags, you may need to use entities for some characters:
            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?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others contemplating the Monastery: (15)
    As of 2014-07-22 14:13 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      My favorite superfluous repetitious redundant duplicative phrase is:









      Results (114 votes), past polls