How do I prevent List::MoreUtils from warning about using $a and $b only once?

前端 未结 6 1779
温柔的废话
温柔的废话 2020-12-15 06:08

The List::MoreUtils module indicates that you use the variables $a and $b when supplying the BLOCK that goes with the pairwise

6条回答
  •  情话喂你
    2020-12-15 06:15

    Depends on what you consider elegant.

    no warnings qw(once);
    our ($a, $b);
    

    One of these two will suffice. You can even limit their scope pretty easily.

    my @sums = pairwise { no warnings qw(once); $a + $b } @x, @y;
    my @sums = pairwise { our $a + our $b } @x, @y;
    

    Explicitly specifying the package will suppress the warning too. If you're in main,

    my @sums = pairwise { $::a + $::b } @x, @y;
    

提交回复
热议问题