pairmap#

Run a block for each pair and concatenate the results.

Σύνοψη#

my @out   = pairmap { BLOCK } @kvlist;
my $count = pairmap { BLOCK } @kvlist;   # scalar context

For every pair the block is called in list context with $a set to the key and $b set to the value; its results are appended to the output list in order.

Τι επιστρέφεται#

In list context, the concatenation of everything every invocation of the block returned. In scalar context, the number of items that would have been returned in list context. $a and $b are aliased to the original list elements - modifications in the block are visible to the caller.

Παραδείγματα#

my @lines = pairmap { "The key $a has value $b" } %hash;
my @flat  = pairmap { ( $a, uc $b ) } %h;   # values upper-cased
my @pairs = pairmap { [ $a, $b ] } %h;      # equivalent to `pairs`

Διαφορές από το upstream#

Fully compatible with upstream.

Δείτε επίσης#

  • pairgrep - filter pairs by a predicate.

  • pairfirst - stop at the first matching pair.

  • pairs - bundle pairs into blessed arrayrefs.