Get hash keys/values on same line as the function call

前端 未结 4 1525
难免孤独
难免孤独 2021-01-15 10:21

Here is the code to reproduce the problem:

sub hello { return (h => 1, n => 1); }
print join \", \", values hello();

I get the error:

4条回答
  •  情书的邮戳
    2021-01-15 10:36

    Another thing that you could do is use a toggle variable.

    sub hello { return (h => 1, n => 1); }
    my $toggle = 1;
    print join ", ", grep { $toggle = !$toggle; } hello();
    

    Another thing you could do is use List::Pairwise

    use List::Pairwise qw;
    print join ", ", mapp { $b } hello();
    

    I had been looking for something to process a list of name-value pairs in a "stream" and even rolled my own, but then I found this on CPAN.

提交回复
热议问题