in reply to Unloading a module completely

Finally got it to work (with lots of warnings) by using plain old Safe. I couldn't get a proper run with Safe::World. I guess is not ready for stable use yet. It has a similar interface to Safe though so one can easilly port to it once it's a bit more stable. Keep up the good work gmpassos.

Thanks to all the monks that have helped me.

Update:

I might be doing it all wrong. I have replacated the failing part(s) here.

This should print 144.

#!/usr/bin/perl use strict; use warnings 'all'; use Safe::World; my ($stdout, $stderr); my $world = Safe::World->new( stdout => \$stdout, stderr => \$stderr, ); print "World created\n"; $world->eval('print 12 ** 2, "\n";'); die $@ if $@; print $stdout, "***End***\n"; # CLEANup should follow

The output produced is the followng (paths foobared):

Scalar value @_[0] better written as $_[0] at .../Safe/World/ScanPack. +pm line 88. Scalar value @_[0] better written as $_[0] at .../Safe/World.pm line 3 +45. Useless use of hash element in void context at .../Safe/World.pm line +1007. Use of uninitialized value in string eq at .../Safe/World.pm line 170. Use of uninitialized value in numeric ne (!=) at .../Safe/World.pm lin +e 344. World created Use of uninitialized value in numeric ne (!=) at .../Safe/World.pm lin +e 386. syntax error at (eval 18) line 1, near "=" Use of uninitialized value in numeric ne (!=) at .../Safe/World.pm lin +e 943. Use of uninitialized value in numeric ne (!=) at .../Safe/World.pm lin +e 956. Use of uninitialized value in numeric ne (!=) at .../Safe/World.pm lin +e 386. Use of uninitialized value in numeric ne (!=) at .../Safe/World.pm lin +e 386. Use of uninitialized value in string ne at .../Safe/World/stdout.pm li +ne 218. Use of uninitialized value in string ne at .../Safe/World/stdout.pm li +ne 218.

Replies are listed 'Best First'.
Re: Re: Unloading a module completely
by gmpassos (Priest) on Dec 09, 2003 at 13:54 UTC
    Note that you need to make a close() after run your code, or you won't have the output flushed! Or you can just use flush in the creation.

    Soo, your code should be:

    use Safe::World; my ($stdout, $stderr); my $world = Safe::World->new( stdout => \$stdout, stderr => \$stderr, ); $world->eval('print 12 ** 2, "\n";'); $world->close ; print $stdout ;
    Or using flush:
    use Safe::World; my ($stdout, $stderr); my $world = Safe::World->new( stdout => \$stdout, stderr => \$stderr, flush => 1 , ); $world->eval('print 12 ** 2, "\n";'); print $stdout ;

    Graciliano M. P.
    "Creativity is the expression of the liberty".