in reply to Re: Re: Why does Perl use dynamic scoping?
in thread Why does Perl use dynamic scoping?

I have to agree with dmerphq here. I can't understand why something so useful gives so many people fits. It's like anything else, you use it where appropriate. dmerphq's code above might as well be mine. I have a global Debug package that provides a $Debug package variable. When I want localized debugging I use a local $Debug = N type declaration. The alternative, as pointed out, is to get/set/replace. I hated doing that with signal handlers in C. When coming to Perl I found it so much cleaner.

How about temporarily overriding STDOUT, or one of the built-ins? For example, I routinely override line delimiters to process files from other systems. What would be the advantage of not being able to dynamically scope these sorts of overrides?

  • Comment on Re: Re: Re: Why does Perl use dynamic scoping?