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);