sub Dump {
no strict 'refs';
my $implementation = __PACKAGE__->implementation;
my $debug; # My own debug variable
for my $option (@dump_options) {
my $var = "$implementation\::$option";
$debug = $var if $var =~/UseCode/; #the option I wish to set
my $value = $$var;
local $$var; # <-- PROBLEM! Local to "for", not "sub"
$$var = defined $value ? $value : ${"YAML::$option"};
# Here I print out the option in each iteration of the loop
print STDERR "$debug = $$debug\n";
}
# And the final value:
print STDERR "FINAL: $debug = $$debug\n";
return &{"$implementation\::Dump"}(@_);
}
####
#!/usr/bin/perl
use strict;
use warnings;
use YAML::Any;
local $YAML::UseCode=1;
my $input = sub {
print "Enter a value: ";
return chomp (my $ret = <>);
};
print Dump $input;
__END__
Name "YAML::UseCode" used only once: possible typo at test.pl line 7.
YAML::XS::UseCode = 1
YAML::XS::UseCode =
YAML::XS::UseCode =
YAML::XS::UseCode =
YAML::XS::UseCode =
YAML::XS::UseCode =
YAML::XS::UseCode =
YAML::XS::UseCode =
YAML::XS::UseCode =
YAML::XS::UseCode =
YAML::XS::UseCode =
YAML::XS::UseCode =
YAML::XS::UseCode =
YAML::XS::UseCode =
YAML::XS::UseCode =
FINAL: YAML::XS::UseCode =
--- !!perl/code '{ "DUMMY" }'
####
#!/usr/bin/perl
use warnings;
use YAML::Any;
local ${YAML::Any->implementation()."::UseCode"}=1;
# can't use strict before this because of refs
use strict;
####
@_=qw;
Just another Perl hacker,;
;$_=q=print
"@_"= and eval;