Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

30. Seven Useful Uses of local > 6. Dynamic Scope Revisited

6. Dynamic Scope Revisited

Here’s another possible use for dynamic scope: you have a subroutine whose behavior depends on the setting of a global variable. This is usually a result of bad design, and should be avoided unless the variable is large and widely used. Suppose that this is the case, and that the variable is called %CONFIG.

You want to call the subroutine, but you want to change its behavior. Perhaps you want to trick it about what the configuration really is, or you want to see what it would do if the configuration were different, or you want to try out a fake configuration to see if it works. But you don’t want to change the real global configuration, because you don’t know what bizarre effects that will have on the rest of the program. Do this:


  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint