shushu has asked for the wisdom of the Perl Monks concerning the following question:
The unsafe code is "unsafe.pl":sub peek_lexicals { my $h = peek_my(2); print "\nlexicals-----------------------\n"; print "keys=", join (", ", keys %$h), "-\n"; print "values=", join (", ", values %$h), "-\n"; print "end of lexicals-----------------------\n"; }
The checking code is "check_code.pl":my $b = 42; $c = "Hallo world\n"; print "printing lexical $b\n"; print "printing global $c\n";
When executed straight ("perl -d:Trace unsafe.pl") I get:use Safe; use Safe::Hole; my $SCRIPT_NAME = "unsafe.pl"; $QTL_HOLE_CPT = new Safe::Hole; $QTL_CPT = new Safe("QTL"); $Devel::Trace_shushu2::TRACE= 1; $QTL_CPT->rdo ( "$SCRIPT_NAME" );
When executed via the checker ("perl -d:Trace_shushu2 check_code.pl") I get:lexicals----------------------- keys=$b- values=SCALAR(0x810811c)- end of lexicals----------------------- lexicals----------------------- keys=$b- values=SCALAR(0x810811c)- end of lexicals----------------------- printing lexical 42 lexicals----------------------- keys=$b- values=SCALAR(0x810811c)- end of lexicals----------------------- printing global Hallo world
* I tried to play with the level given to the &peek_my, with no good effect.lexicals----------------------- keys=$SCRIPT_NAME- values=SCALAR(0x8108144)- end of lexicals----------------------- lexicals----------------------- keys=$SCRIPT_NAME- values=SCALAR(0x8108144)- end of lexicals----------------------- lexicals----------------------- keys=$SCRIPT_NAME- values=SCALAR(0x8108144)- end of lexicals----------------------- lexicals----------------------- keys=$default_share, $default_root, $VERSION- values=SCALAR(0x824f76c), SCALAR(0x810b704), SCALAR(0x8225304)- end of lexicals----------------------- lexicals----------------------- keys=$default_share, $default_root, $VERSION- values=SCALAR(0x824f76c), SCALAR(0x810b704), SCALAR(0x8225304)- end of lexicals----------------------- lexicals----------------------- keys=$default_share, $default_root, $VERSION- values=SCALAR(0x824f76c), SCALAR(0x810b704), SCALAR(0x8225304)- end of lexicals----------------------- printing lexical 42 lexicals----------------------- keys=$default_share, $default_root, $VERSION- values=SCALAR(0x824f76c), SCALAR(0x810b704), SCALAR(0x8225304)- end of lexicals----------------------- printing global Hallo world
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: PadWalker and Safe - getting the lexicals
by robin (Chaplain) on Oct 10, 2002 at 12:26 UTC | |
by Anonymous Monk on Oct 10, 2002 at 13:41 UTC | |
by shushu (Scribe) on Oct 10, 2002 at 14:01 UTC | |
by shushu (Scribe) on Oct 10, 2002 at 15:43 UTC | |
by shushu (Scribe) on Oct 13, 2002 at 15:33 UTC | |
by diotalevi (Canon) on Oct 13, 2002 at 15:46 UTC |