R
Richard A. DeVenezia
This doesn't assign variables. Then commented out 'eval join' version does.
Why doesn't the first version work ?
#!perl -w
use strict;
doStuff (a=>1, b=>2, c=>'foo', foo=>'bar', z=>9);
sub doStuff {
my %param = @_;
my ($a, $b, $c);
my @allowed = qw (a b c);
no strict 'refs';
map $$_ = $param{$_}, @allowed;
use strict;
# eval join ("", map "\$$_ = \$param{'$_'};", @allowed);
print "a=$a\nb=$b\nc=$c\n";
}
Why doesn't the first version work ?
#!perl -w
use strict;
doStuff (a=>1, b=>2, c=>'foo', foo=>'bar', z=>9);
sub doStuff {
my %param = @_;
my ($a, $b, $c);
my @allowed = qw (a b c);
no strict 'refs';
map $$_ = $param{$_}, @allowed;
use strict;
# eval join ("", map "\$$_ = \$param{'$_'};", @allowed);
print "a=$a\nb=$b\nc=$c\n";
}