In Perl, is it appropriate to use map in void context instead of a foreach loop?

前端 未结 3 1935
遥遥无期
遥遥无期 2020-12-03 08:31

In Perl, if you have a loop like this:

foreach (@items) {
    perform_action($_);
}

you can replace it with a call to map in v

3条回答
  •  我在风中等你
    2020-12-03 08:50

    I believe 'Perl Best Practices' would recommend using an explicit variable in the foreach loop as the best style - it is certainly what I'd use.

    foreach my $item (@items)
    {
        perform_action($item);
    }
    

    It is an abuse of map (or grep) to use it in a void context.

提交回复
热议问题