Hello all!

I am in need of some wisdom. I am working on what is becoming an ever more enormous script (about 4000 lines now and still growing, but mostly because it employs the Tk module to build a gui to a database), and beginning to worry about the way that I'm passing variables to the various subroutines.

Until writing this script, I had always passed variables to subroutines via @_ (and had blindly assumed that was the only way), but this script requires access to a number of pseudo-constants (values that are not constant, but the user is limited to only certain selections). Consequently, after a little investigation, I discovered that you could access globally scoped 'my' variables from within subroutines, so rather than needlessly keep passing the same pseudo-constants to each subroutine, I just started accessing them as I would within any other block of code.

Now that I'm nearing the end of this phase of the project, I'm starting to look at the code for any missed bugs or obvious failures, and this (what seems to me now possibly reckless) use of variables has me worried.

So I guess my question is, does anyone see any obvious failures in this approach? I realize that passing variables by reference will prevent accidental modifications of the original, but these values are never modified in the subroutines (i.e., they are used to specify which database to access, etc.). Anyone want to pat me on the head and reassure that I haven't committed a heinous coding crime?

Thanks in advance,

matt


In reply to Passing variables is as easy as passing gas by mattg

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.