Name

reduce

Synopsis

reduce { BLOCK } @list
                  

Literally “reduces” @ list by calling BLOCK until there are no more items to operate on in @ list. reduce sets $a and $b for each operation in BLOCK and returns the reduced list as a scalar. If @ list is 0, BLOCK is not executed, and $ list [0] is returned. If @list is empty, then reduce returns undef.

You can sum and concatenate a list using reduce like so:

my $sum_of_list = reduce { $a + $b } @ll; # sum
my $concat_list = reduce { $a . $b } @ll; # concat

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.117.138.104