[英]How do I return values from a Perl method in a Vim script?
I'm writing a Vim script. 我正在写一个Vim脚本。 I have a function that uses embedded Perl. 我有一个使用嵌入式Perl的函数。 How do I return values from my Perl code? 如何从Perl代码返回值?
The key is to escape any single quotes in the value you are trying to return, and then use VIM::DoCommand("return '$data'")
. 关键是要逃避您尝试返回的值中的任何单引号,然后使用VIM::DoCommand("return '$data'")
。
For example: 例如:
function PhoneHome()
perl << EOF
use IO::Socket;
my $mothership = IO::Socket->INET->connect()
my $data = <$mothership>;
$data =~ s|'|''|g; # escape '
VIM::DoCommand("return '$data'")
EOF
endfunction
Also see :help perl
and :help perl-DoCommand
. 另请参阅:help perl
和:help perl-DoCommand
。 But for the most part this is not really documented. 但在大多数情况下,这并没有真正记录在案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.