in reply to Re: use depending on environment
in thread use depending on environment
Addmittedly, it is seems odd that
does not do what you expect; but it makes more sense if you think of what it really does. Convert the above code intoBEGIN { if ($condition) { use Foo; } }
BEGIN { if ($condition) { BEGIN { require Foo; Foo::import(); } } }
Then remember that if you have this:
you have created a real subroutine called "old" in package Bar that can be called. The same is true with the use inside the BEGIN { }; you created a real BEGIN { } block that will be executed at compile time in the order in which it was encountered. You will actually execute that code regardless of the if { } block that surrounds it.print Bar::new(); print Bar::old(); package Bar; sub new { sub old { return "I'm old"; } return "I'm new"; } 1;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: use depending on environment
by tlm (Prior) on Jun 22, 2005 at 17:18 UTC | |
|
Re^3: use depending on environment - ok
by Andre_br (Pilgrim) on Jun 22, 2005 at 20:40 UTC | |
by jhourcle (Prior) on Jun 22, 2005 at 23:23 UTC | |
|
Re^3: use depending on environment
by Andre_br (Pilgrim) on Jun 22, 2005 at 19:42 UTC | |
|
Re^3: use depending on environment
by Andre_br (Pilgrim) on Jun 22, 2005 at 19:50 UTC | |
by QM (Parson) on Jun 22, 2005 at 20:33 UTC |