[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [FWP] namespace problem (fwd)



In article <Pine.GSO.4.21.0006062240270.27325-100000@crusoe.crusoe.net>,
Jeff Pinyan <jeffp@crusoe.net> wrote:
> 
> This assumes, though, that you want to call a FUNCTION in other.pl -- if
> you want to RUN the entire file "other.pl", but disregard the fact that
> it's in another package...
> 
>   ### other.pl
>   package Outside;
>   print $VAR;
>   $VAR *= 2;
> 
>   ### main.pl
>   $VAR = 300;
>   {
>     my @to_copy = grep !/^main::/, keys %main::;
>     @Outside::{@to_copy} = @main::{@to_copy};
>     require "other.pl";  # prints $main::VAR, and makes it 600
>     @main::{@to_copy} = @Outside::{@to_copy};
>   }
>   print $VAR;  # 600

### main.pl
$VAR = 300;
*Outside:: = *main::;  # could be localized if desired
require "other.pl";

==== Want to unsubscribe from Fun With Perl?  Well, if you insist...
==== Send email to <fwp-request@technofile.org> with message _body_
====   unsubscribe