in reply to Re: Parameter injection for testing
in thread [Solved] Parameter injection for testing
here a little demo using eval
NB: the allowed vars must be bound inside the setter sub, otherwise the eval will fail.
use v5.12; use warnings; { package TEST; my $param = 666; sub getset { my %args = @_; return [$param] # list of allowed vars unless @_; while ( my ( $var, $val ) = each %args ) { eval "$var = $val"; } } sub show { say $param; } } package main; TEST::show(); TEST::getset( '$param' => 42 ); TEST::show();
666 42
Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery
|
|---|