<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;"># List::Util.pm
#
# Copyright (c) 1997-2005 Graham Barr &lt;gbarr@pobox.com&gt;. All rights reserved.
# This program is free software; you can redistribute it and/or
# modify it under the same terms as Perl itself.

package List::Util;

use strict;
use vars qw(@ISA @EXPORT_OK $VERSION $XS_VERSION $TESTING_PERL_ONLY);
require Exporter;

@ISA        = qw(Exporter);
@EXPORT_OK  = qw(first min max minstr maxstr reduce sum shuffle);
$VERSION    = "1.18";
$XS_VERSION = $VERSION;
$VERSION    = eval $VERSION;

eval {
  # PERL_DL_NONLAZY must be false, or any errors in loading will just
  # cause the perl code to be tested
  local $ENV{PERL_DL_NONLAZY} = 0 if $ENV{PERL_DL_NONLAZY};
  eval {
    require XSLoader;
    XSLoader::load('List::Util', $XS_VERSION);
    1;
  } or do {
    require DynaLoader;
    local @ISA = qw(DynaLoader);
    bootstrap List::Util $XS_VERSION;
  };
} unless $TESTING_PERL_ONLY;

# This code is only compiled if the XS did not load
# of for perl &lt; 5.6.0

if (!defined &amp;reduce) {
eval &lt;&lt;'ESQ' 

sub reduce (&amp;@) {
  my $code = shift;
  no strict 'refs';

  return shift unless @_ &gt; 1;

  use vars qw($a $b);

  my $caller = caller;
  local(*{$caller."::a"}) = \my $a;
  local(*{$caller."::b"}) = \my $b;

  $a = shift;
  foreach (@_) {
    $b = $_;
    $a = &amp;{$code}();
  }

  $a;
}

sub first (&amp;@) {
  my $code = shift;

  foreach (@_) {
    return $_ if &amp;{$code}();
  }

  undef;
}

ESQ
}

# This code is only compiled if the XS did not load
eval &lt;&lt;'ESQ' if !defined &amp;sum;

use vars qw($a $b);

sub sum (@) { reduce { $a + $b } @_ }

sub min (@) { reduce { $a &lt; $b ? $a : $b } @_ }

sub max (@) { reduce { $a &gt; $b ? $a : $b } @_ }

sub minstr (@) { reduce { $a lt $b ? $a : $b } @_ }

sub maxstr (@) { reduce { $a gt $b ? $a : $b } @_ }

sub shuffle (@) {
  my @a=\(@_);
  my $n;
  my $i=@_;
  map {
    $n = rand($i--);
    (${$a[$n]}, $a[$n] = $a[$i])[0];
  } @_;
}

ESQ

1;

__END__

</pre></body></html>