My reaction to what you describe is that both of you need to improve on design so that you don't think that you really need 30 variables all of the time. I wish I had a simple way to tell you how to do that, but without understanding why you are getting into that bind, I cannot really tell you how to avoid needing that many variables. (I suspect that understanding that phrase, Think loose coupling that you see from time to time on pages here might help.)

But after that, both solutions have problems. Globals raise the possibility of promiscuous interaction between code, which causes all of the usual debugging issues. Passing variables protects you from that, and documents what you are using, but raises issues with how your argument lists are structured. If you are positionally placing 30 arguments, then you are using copy and paste. What happens if you want to add an argument? Hopefully you are using hashes to allow you to work by name.

Likewise the answers that people are offering have issues. If you start using hashes, how do you do typo checks? I have offered solutions to that in the past. But most of those solutions (rightly IMO) require you to wind up carefully thinking through which variables are needed in which functions. Passing references to hashes you directly access is likewise problematical for the reasons that I stated at Pass by reference vs globals.

No. The real problem is that you are trying to manage a large amount of common data. That is a task which raises inherent issues. And solving that is probably a design issue.


In reply to Re (tilly) 1: Use globals or pass around everything under the sun? by tilly
in thread Use globals or pass around everything under the sun? by greywolf

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.