in reply to Re^2: Global variable vs passing variable from sub to sub
in thread Global variable vs passing variable from sub to sub

This node falls below the community's threshold of quality. You may see it by logging in.
  • Comment on Re^3: Global variable vs passing variable from sub to sub

Replies are listed 'Best First'.
Re^4: Global variable vs passing variable from sub to sub
by Rhys (Pilgrim) on Sep 14, 2004 at 22:52 UTC
    Wassercrats,

    While I agree that debugging code - particularly code that you're still familiar with - is usually just as easy/difficult with or without globals, the Real Reason that I have discovered that people scope things and use 'my' are as follows:

    People use 'my' along with 'use strict' to make sure typos don't get taken seriously. Auto-vivification is cool in some contexts, but I just plain don't see the difference between $options{debug} and $optoins{debug}. Perl does, though, if %options is declared and I have 'use strict' enabled. This has saved me hours of debugging time chasing typos.

    People use local variables in subs because they like to turn them into modules that get used in other programs, and sometimes those other programs already have another variable - used for something else - by the same name. I always use $mib, $sess, $var, $vb, and $vl in my SNMP-related scripts. Straight from the man page for SNMP.pm. This would be a problem if I didn't do a lot of my code in modules (along with 'use strict', 'my', etc. etc.).

    I don't find that having local vs. global variables has helped my debugging any, though (not that I use proper debugging techniques, AFAIK).

    --J

    A reply falls below the community's threshold of quality. You may see it by logging in.
Re^4: Global variable vs passing variable from sub to sub
by Pragma (Scribe) on Sep 15, 2004 at 03:10 UTC
    I won't read ...
    Ah, Wassercrats. We know.
Re^4: Global variable vs passing variable from sub to sub
by Anonymous Monk on Sep 15, 2004 at 03:52 UTC
    I find the arguments in this thread to be lacking substance

    And then all you provide are arguments like

    The effort it takes to properly scope variables, which often requires a different code structure, outweighs the problems I've encountered using globals.

    with no explanation whatsoever about what you find so difficult about scoping variables.


    I'll summarize everyone else's arguments into a form which contains the same amount of "substance" (You keep using that word... I do not think it means what you think it means--Inigo Montoya) as your posts: Scoping variables takes no additional effort and it eliminates one potential source of bugs.

    A reply falls below the community's threshold of quality. You may see it by logging in.