3 # Copyright (c) 1997-2009 Graham Barr <gbarr@pobox.com>. All rights reserved.
4 # This program is free software; you can redistribute it and/or
5 # modify it under the same terms as Perl itself.
7 package List::Util::PP;
11 use vars qw(@ISA @EXPORT $VERSION $a $b);
15 @EXPORT = qw(first min max minstr maxstr reduce sum shuffle);
17 $VERSION = eval $VERSION;
22 my $type = Scalar::Util::reftype($code);
23 unless($type and $type eq 'CODE') {
25 Carp::croak("Not a subroutine reference");
29 return shift unless @_ > 1;
34 local(*{$caller."::a"}) = \my $a;
35 local(*{$caller."::b"}) = \my $b;
49 my $type = Scalar::Util::reftype($code);
50 unless($type and $type eq 'CODE') {
52 Carp::croak("Not a subroutine reference");
56 return $_ if &{$code}();
63 sub sum (@) { reduce { $a + $b } @_ }
65 sub min (@) { reduce { $a < $b ? $a : $b } @_ }
67 sub max (@) { reduce { $a > $b ? $a : $b } @_ }
69 sub minstr (@) { reduce { $a lt $b ? $a : $b } @_ }
71 sub maxstr (@) { reduce { $a gt $b ? $a : $b } @_ }
79 (${$a[$n]}, $a[$n] = $a[$i])[0];