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

I see that as a variation on levels of function calls. You want to know whether you are in the function call in question.

But there are several ways to do the above. One crazy approach is to write a function set_debugging that replaces a function with a wrapped version that sets and unsets debugging as above. Take a look at the implementation of Memoize if you need hints on how to do that. Or for methods you can use Class::Contract and set pre and post conditions. Once written, using it is easy.

Still this is a case where dynamic scope makes it simple and handles hard cases like unexpected interior exits - possibly from a die/eval pair.

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

Replies are listed 'Best First'.
Re: Re: Re: Re: Why does Perl use dynamic scoping?
by demerphq (Chancellor) on Feb 08, 2003 at 00:41 UTC
    You want to know whether you are in the function call in question.

    Yeah I can see your point. But as you said most of the other ways are inconvient and inefficient, not to mention less flexible. For instance perlfunc:caller provides a way to determine if you have been called below a given sub, just walk the stack and see, but it would be slow and clumsy. Also in addition to your last point localization provides the benefit of applying to blocks and not just subs.

    As adrianh said, I dont want globals or dynamic scoping often, but when I want them I want them there. :-)

    Minor typographical changes were made to this node after it was posted.

    --- demerphq
    my friends call me, usually because I'm late....