To begin with, accessing global variables from a subroutine is poor programming practice.

If you have a large number of separate variables, I bet some of them belong together, just like the left and right headlights and left and right windshield wipers and the four tires on my car belong together. You could combine these into a more complex data structure, a car, and then pass only one variable, instead of eight.

Instead of passing the variable, and having the data copied inside the routine, and then copied again on the return from the routine, pass a referencece to the variable, so that no copying is done at all.

if you've now grouped variables and routines into various categories, say those dealing with your car, those dealing with your kitchen, those dealing with your printer, aggregate the data and routines into objects. While it may seem excessive for a small project, the objects will probably be small and simple, and hopefully you can re-use them in other projects. Type perldoc perlboot ( then perldoc perltoot1, and next perldoc perltoot2 ) to learn about objects, and then buy Randall Schwatrz's Learning Perl Objects, References & Modules to perfect your understanding.

--
TTTATCGGTCGTTATATAGATGTTTGCA


In reply to Re: Global vars? by TomDLux
in thread Global vars? by mfuller

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.