7 require Config; import Config;
8 keys %Config; # Silence warning
9 if ($Config{extensions} !~ /\bList\/Util\b/) {
10 print "1..0 # Skip: List::Util was not built\n";
17 use List::Util qw(reduce min);
21 print "not " if defined reduce {};
24 print "not " unless 9 == reduce { $a / $b } 756,3,7,4;
27 print "not " unless 9 == reduce { $a / $b } 9;
30 @a = map { rand } 0 .. 20;
31 print "not " unless min(@a) == reduce { $a < $b ? $a : $b } @a;
34 @a = map { pack("C", int(rand(256))) } 0 .. 20;
35 print "not " unless join("",@a) eq reduce { $a . $b } @a;
43 my $sum = reduce { my $t="$a $b\n"; 0+add($a, $b) } 3, 2, 1;
44 print "not " unless $sum == 6;
47 # Check that eval{} inside the block works correctly
48 print "not " unless 10 == reduce { eval { die }; $a + $b } 0,1,2,3,4;
51 print "not " if defined eval { reduce { die if $b > 2; $a + $b } 0,1,2,3,4 };
57 sub foobar { reduce { (defined(wantarray) && !wantarray) ? '' : 'not ' } 0,1,2,3 }