I'm trying to write an alias that will let me pass a
parameter to a called subroutine. This is an example
target subroutine:
my $targetsub = sub {
my $target = (@_);
$::world->echonl($target);
return undef;
};
I can't have a direct subroutine call in an s/// set,
but I can use a reference, hence the syntax above.
This works, when loaded into a plugin:
$::world->alias({
name => "achaea:tb",
pattern => qr/^sen (.+)$/o,
substitution => '"sense $1"',
perleval => 1,
});
This doesn't:
$::world->alias({
name => "achaea:tar",
pattern => qr/^tar (.+)$/o,
substitution => qr/&$targetsub($1)/xo,
perleval => 1,
});
But this does:
$::world->alias({
name => "achaea:tar",
pattern => qr/^tar (.+)$/o,
substitution => qr/&$targetsub()/xo,
perleval => 1,
});
I'm not certain why. The syntax above that doesn't work
in kildclient does work on the command line:
perl -we 'my $xxx = sub { print "this is $_[0] xxx
sub\n"}; my $text = "tb xyz"; $text =~ s/tb
(.+)/&$xxx($1)/e'
(Of course, can't 'use strict' or it will break.)
Is there a way to use a subroutine as the action for an
alias? If not, perhaps I'll make a feature request.
I can't code in C++, but I'm willing to offer other help.