in reply to subroutines and namespace

You can't (and, while not strictly crazy to want this, you are... misguided... or unwise...).

The point about statically scoped (my) variables is that what they refer to can be completely determined by their point of definition. So if I say

my $foo=17; sub quux { my $bar=29; $foo = baz($foo,++$bar) }
then it is possible, just by examining the point of definition of quux, to determine what gets modified where.

What you're after is global variables. You want some variable defined in one place in your program to get modified in an entirely different place. Why is this bad?

Well, consider this code:

use vars qw/$foo/; sub quux { my $bar=29; $foo = baz($foo,++$bar) } # ...code passes... $foo = 11; print quux($foo), "\n"; # ...more code... { local $foo = 39; print quux($foo), "\n"; }
Note how every time some other $foo gets modified. Just by examining the new definition of quux you get no clues as to what gets modified. Instead, you have to examine the point where quux gets called, then work your way up the call stacks to surrounding blocks. You examine each block to see if local $foo sets up a new copy, or find $foo at the top level. And that's the copy of $foo that gets modified.

Variable lookup with global variables is akin to spaghetti. You can eat it, but there are healthier alternatives...

Replies are listed 'Best First'.
Re2: subroutines and namespace
by dragonchild (Archbishop) on Nov 02, 2001 at 19:49 UTC
    Yeah, but nothing else that takes 5 minutes to make tastes as good. (Maybe that's an analogy?)

    ------
    We are the carpenters and bricklayers of the Information Age.

    Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.