开发者

In Perl, how do you create a reference to the output of a subroutine without using an intermediate variable?

开发者 https://www.devze.com 2023-02-07 07:48 出处:网络
Suppose I have a list called @emailList, and I would like to pass a reference to that list to a subroutine called sendEmail.I开发者_Python百科 know I can do it this way:

Suppose I have a list called @emailList, and I would like to pass a reference to that list to a subroutine called sendEmail. I开发者_Python百科 know I can do it this way:

my @emailList = split(/[$EMAIL_DELIMS]+/, $emailListStr);
sendEmail(\@emailList);

But if I want to create a reference to the output of split directly without using the intermediate variable @emailList, what's the correct syntax? I have already tried:

sendEmail(\@{split(/[$EMAIL_DELIMS]+/, $emailListStr)});

… as well as many subtle variations of this, but perl always complains. Suggestions?


sendEmail([ split(/[$EMAIL_DELIMS]+/, $emailListStr) ]);

will create an anonymous array populated using the list returned by split and pass it to sendEmail.

Also, you might want to use Email::Address->parse.

0

精彩评论

暂无评论...
验证码 换一张
取 消