Here's a trick for interpolating a subroutine call into a string:
- print "My sub returned @{[mysub(1,2,3)]} that time.\n";
The way it works is that when the
@{...}
is seen in the double-quoted string, it's evaluated as a block. The block creates a reference to an anonymous array containing the results of the call tomysub(1,2,3)
. So the whole block returns a reference to an array, which is then dereferenced by@{...}
and stuck into the double-quoted string.
--
您收到此邮件是因为您订阅了 Google 网上论坛“PerlChina Mongers 讨论组”中的主题。
要退订此主题,请访问 https://groups.google.com/d/topic/perlchina/K5yBGT3JgI4/unsubscribe?hl=zh-CN。
要退订此论坛及其所有主题,请发送电子邮件到 perlchina+...@googlegroups.com。
要向此网上论坛发帖,请发送电子邮件至 perl...@googlegroups.com。
通过以下网址访问此论坛:http://groups.google.com/group/perlchina?hl=zh-CN。
要查看更多选项,请访问 https://groups.google.com/groups/opt_out。