使用 Perl 5+,此代码是否映射我的内部数组?
package somepackage;
(...)
sub someMappingFunction (\&@) {
my $this = shift;
#well should not because the object is supposed
#to a blessed hash reference and not a function.
my $f = shift;
map { &$f($_) } $this->{'some_internal_array'};
}
如何更正它以便以这种方式调用该函数?
sub create_mapping_function {
# this is even more complicated in my real application!
my $value = shift;
my $key = shift;
return sub {
my $line = shift;
$line=~s/$key/$value/;
return $line;
}
}
(... long, very long ...)
myObject->someMappingFunction create_mapping_function('$option',42);
(...)
mySecondObject->someMappingFunction create_mapping_function('$option',65);