The biggest issue is "action at a distance". That is, it is much harder to ensure correct management of global variables because the code that may affect them may be scattered through the code base. That makes it hard to think about how the various places that may alter or use a global variable interact.

For trivial code it doesn't matter at all. But the use of global variables don't scale well as code size increases.

A significant exception to the "don't use globals" guideline is using global constants. Because they are constant there is no issue with figuring out how their value may change (it doesn't - they are constants!). Using global constants to manage things like scaling coefficients or other magic values is vastly better than using manifest constants.

Optimising for fewest key strokes only makes sense transmitting to Pluto or beyond

In reply to Re^3: Common subs and Global Variables by GrandFather
in thread Common subs and Global Variables by Anonymous Monk

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.