Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
I won't read through the tutorials to learn what that last line does. I recognize all the operators, but can't be sure what it does without looking stuff up. The use of "&&" confuses me. It looks like some boolian structure that I used to know how to use, or maybe it's an ordinary logical "and", but I'd like to see parentheses in that case because I never remember the order of operations of things.

I recognized the hash, but I'm unsure about the the use of "exists". I guess it's being used for the 1 or 0 value, but I don't think that's how it's usually used. I wouldn't use hashes when teaching something not related to hashes. I've only used them once when I wrote Varstructor, which had to parse code that might contain hashes, and maybe another time for that duplicate elimination trick.

In the second block of code, I just didn't get the point. Maybe I didn't try hard enough, but a better explanation would have helped.

No matter what code you use in an example, it helps to explain what it does.

...*any* single one of those 11,000 lines can modify that global value. Therefor, when your global has the *wrong* value, you have problems finding it, because you must examine 11,000 lines of code.

After I posted that reply I realized that might the person's point, but he mentioned having to step through the code with a debugger, which wouldn't be necessary. Is it really so hard to search the code for the variable in question? Even Wordpad, which I'm still using for now, could do that. With globals, you don't have to check to see if you passed the value on to another routine. You merely search for a variable by name.

As I mentioned in another thread, if you change plans and want to call a variable that was lexically scoped a few routines ago, things get complicated.

I find the arguments in this thread to be lacking substance. The effort it takes to properly scope variables, which often requires a different code structure, outweighs the problems I've encountered using globals. Globals mean less planning ahead, EASIER debugging, and, using the definition of "safe" that people have used with me, safer code.


In reply to Re^3: Global variable vs passing variable from sub to sub by Wassercrats
in thread Global variable vs passing variable from sub to sub by kiat

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (4)
As of 2024-04-25 13:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found