Edit D:\app\Administrator\product\11.2.0\dbhome_1\perl\html\lib\List\Util.html
<?xml version="1.0" ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>List::Util - A selection of general-utility list subroutines</title> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <link rev="made" href="mailto:" /> </head> <body style="background-color: white"> <table border="0" width="100%" cellspacing="0" cellpadding="3"> <tr><td class="block" style="background-color: #cccccc" valign="middle"> <big><strong><span class="block"> List::Util - A selection of general-utility list subroutines</span></strong></big> </td></tr> </table> <!-- INDEX BEGIN --> <div name="index"> <p><a name="__index__"></a></p> <ul> <li><a href="#name">NAME</a></li> <li><a href="#synopsis">SYNOPSIS</a></li> <li><a href="#description">DESCRIPTION</a></li> <li><a href="#known_bugs">KNOWN BUGS</a></li> <li><a href="#suggested_additions">SUGGESTED ADDITIONS</a></li> <li><a href="#see_also">SEE ALSO</a></li> <li><a href="#copyright">COPYRIGHT</a></li> </ul> <hr name="index" /> </div> <!-- INDEX END --> <p> </p> <h1><a name="name">NAME</a></h1> <p>List::Util - A selection of general-utility list subroutines</p> <p> </p> <hr /> <h1><a name="synopsis">SYNOPSIS</a></h1> <pre> use List::Util qw(first max maxstr min minstr reduce shuffle sum);</pre> <p> </p> <hr /> <h1><a name="description">DESCRIPTION</a></h1> <p><code>List::Util</code> contains a selection of subroutines that people have expressed would be nice to have in the perl core, but the usage would not really be high enough to warrant the use of a keyword, and the size so small such that being individual extensions would be wasteful.</p> <p>By default <code>List::Util</code> does not export any subroutines. The subroutines defined are</p> <dl> <dt><strong><a name="first" class="item">first BLOCK LIST</a></strong> <dd> <p>Similar to <a href="file://C|\ADE\aime_smenon_perl_090715\perl\html/pod/perlfunc.html#grep"><code>grep</code></a> in that it evaluates BLOCK setting <a href="file://C|\ADE\aime_smenon_perl_090715\perl\html/pod/perlvar.html#__"><code>$_</code></a> to each element of LIST in turn. <a href="#first"><code>first</code></a> returns the first element where the result from BLOCK is a true value. If BLOCK never returns true or LIST was empty then <a href="file://C|\ADE\aime_smenon_perl_090715\perl\html/pod/perlfunc.html#undef"><code>undef</code></a> is returned.</p> </dd> <dd> <pre> $foo = first { defined($_) } @list # first defined value in @list $foo = first { $_ > $value } @list # first value in @list which # is greater than $value</pre> </dd> <dd> <p>This function could be implemented using <a href="#reduce"><code>reduce</code></a> like this</p> </dd> <dd> <pre> $foo = reduce { defined($a) ? $a : wanted($b) ? $b : undef } undef, @list</pre> </dd> <dd> <p>for example <code>wanted()</code> could be <a href="file://C|\ADE\aime_smenon_perl_090715\perl\html/pod/perlfunc.html#defined"><code>defined()</code></a> which would return the first defined value in @list</p> </dd> </li> <dt><strong><a name="max" class="item">max LIST</a></strong> <dd> <p>Returns the entry in the list with the highest numerical value. If the list is empty then <a href="file://C|\ADE\aime_smenon_perl_090715\perl\html/pod/perlfunc.html#undef"><code>undef</code></a> is returned.</p> </dd> <dd> <pre> $foo = max 1..10 # 10 $foo = max 3,9,12 # 12 $foo = max @bar, @baz # whatever</pre> </dd> <dd> <p>This function could be implemented using <a href="#reduce"><code>reduce</code></a> like this</p> </dd> <dd> <pre> $foo = reduce { $a > $b ? $a : $b } 1..10</pre> </dd> </li> <dt><strong><a name="maxstr" class="item">maxstr LIST</a></strong> <dd> <p>Similar to <a href="#max"><code>max</code></a>, but treats all the entries in the list as strings and returns the highest string as defined by the <code>gt</code> operator. If the list is empty then <a href="file://C|\ADE\aime_smenon_perl_090715\perl\html/pod/perlfunc.html#undef"><code>undef</code></a> is returned.</p> </dd> <dd> <pre> $foo = maxstr 'A'..'Z' # 'Z' $foo = maxstr "hello","world" # "world" $foo = maxstr @bar, @baz # whatever</pre> </dd> <dd> <p>This function could be implemented using <a href="#reduce"><code>reduce</code></a> like this</p> </dd> <dd> <pre> $foo = reduce { $a gt $b ? $a : $b } 'A'..'Z'</pre> </dd> </li> <dt><strong><a name="min" class="item">min LIST</a></strong> <dd> <p>Similar to <a href="#max"><code>max</code></a> but returns the entry in the list with the lowest numerical value. If the list is empty then <a href="file://C|\ADE\aime_smenon_perl_090715\perl\html/pod/perlfunc.html#undef"><code>undef</code></a> is returned.</p> </dd> <dd> <pre> $foo = min 1..10 # 1 $foo = min 3,9,12 # 3 $foo = min @bar, @baz # whatever</pre> </dd> <dd> <p>This function could be implemented using <a href="#reduce"><code>reduce</code></a> like this</p> </dd> <dd> <pre> $foo = reduce { $a < $b ? $a : $b } 1..10</pre> </dd> </li> <dt><strong><a name="minstr" class="item">minstr LIST</a></strong> <dd> <p>Similar to <a href="#min"><code>min</code></a>, but treats all the entries in the list as strings and returns the lowest string as defined by the <code>lt</code> operator. If the list is empty then <a href="file://C|\ADE\aime_smenon_perl_090715\perl\html/pod/perlfunc.html#undef"><code>undef</code></a> is returned.</p> </dd> <dd> <pre> $foo = minstr 'A'..'Z' # 'A' $foo = minstr "hello","world" # "hello" $foo = minstr @bar, @baz # whatever</pre> </dd> <dd> <p>This function could be implemented using <a href="#reduce"><code>reduce</code></a> like this</p> </dd> <dd> <pre> $foo = reduce { $a lt $b ? $a : $b } 'A'..'Z'</pre> </dd> </li> <dt><strong><a name="reduce" class="item">reduce BLOCK LIST</a></strong> <dd> <p>Reduces LIST by calling BLOCK, in a scalar context, multiple times, setting <a href="file://C|\ADE\aime_smenon_perl_090715\perl\html/pod/perlvar.html#_a"><code>$a</code></a> and <a href="file://C|\ADE\aime_smenon_perl_090715\perl\html/pod/perlvar.html#_b"><code>$b</code></a> each time. The first call will be with <a href="file://C|\ADE\aime_smenon_perl_090715\perl\html/pod/perlvar.html#_a"><code>$a</code></a> and <a href="file://C|\ADE\aime_smenon_perl_090715\perl\html/pod/perlvar.html#_b"><code>$b</code></a> set to the first two elements of the list, subsequent calls will be done by setting <a href="file://C|\ADE\aime_smenon_perl_090715\perl\html/pod/perlvar.html#_a"><code>$a</code></a> to the result of the previous call and <a href="file://C|\ADE\aime_smenon_perl_090715\perl\html/pod/perlvar.html#_b"><code>$b</code></a> to the next element in the list.</p> </dd> <dd> <p>Returns the result of the last call to BLOCK. If LIST is empty then <a href="file://C|\ADE\aime_smenon_perl_090715\perl\html/pod/perlfunc.html#undef"><code>undef</code></a> is returned. If LIST only contains one element then that element is returned and BLOCK is not executed.</p> </dd> <dd> <pre> $foo = reduce { $a < $b ? $a : $b } 1..10 # min $foo = reduce { $a lt $b ? $a : $b } 'aa'..'zz' # minstr $foo = reduce { $a + $b } 1 .. 10 # sum $foo = reduce { $a . $b } @bar # concat</pre> </dd> </li> <dt><strong><a name="shuffle" class="item">shuffle LIST</a></strong> <dd> <p>Returns the elements of LIST in a random order</p> </dd> <dd> <pre> @cards = shuffle 0..51 # 0..51 in a random order</pre> </dd> </li> <dt><strong><a name="sum" class="item">sum LIST</a></strong> <dd> <p>Returns the sum of all the elements in LIST. If LIST is empty then <a href="file://C|\ADE\aime_smenon_perl_090715\perl\html/pod/perlfunc.html#undef"><code>undef</code></a> is returned.</p> </dd> <dd> <pre> $foo = sum 1..10 # 55 $foo = sum 3,9,12 # 24 $foo = sum @bar, @baz # whatever</pre> </dd> <dd> <p>This function could be implemented using <a href="#reduce"><code>reduce</code></a> like this</p> </dd> <dd> <pre> $foo = reduce { $a + $b } 1..10</pre> </dd> </li> </dl> <p> </p> <hr /> <h1><a name="known_bugs">KNOWN BUGS</a></h1> <p>With perl versions prior to 5.005 there are some cases where reduce will return an incorrect result. This will show up as test 7 of reduce.t failing.</p> <p> </p> <hr /> <h1><a name="suggested_additions">SUGGESTED ADDITIONS</a></h1> <p>The following are additions that have been requested, but I have been reluctant to add due to them being very simple to implement in perl</p> <pre> # One argument is true</pre> <pre> sub any { $_ && return 1 for @_; 0 }</pre> <pre> # All arguments are true</pre> <pre> sub all { $_ || return 0 for @_; 1 }</pre> <pre> # All arguments are false</pre> <pre> sub none { $_ && return 0 for @_; 1 }</pre> <pre> # One argument is false</pre> <pre> sub notall { $_ || return 1 for @_; 0 }</pre> <pre> # How many elements are true</pre> <pre> sub true { scalar grep { $_ } @_ }</pre> <pre> # How many elements are false</pre> <pre> sub false { scalar grep { !$_ } @_ }</pre> <p> </p> <hr /> <h1><a name="see_also">SEE ALSO</a></h1> <p><a href="file://C|\ADE\aime_smenon_perl_090715\perl\html/lib/Scalar/Util.html">the Scalar::Util manpage</a>, <a href="file://C|\ADE\aime_smenon_perl_090715\perl\html/List/MoreUtils.html">the List::MoreUtils manpage</a></p> <p> </p> <hr /> <h1><a name="copyright">COPYRIGHT</a></h1> <p>Copyright (c) 1997-2006 Graham Barr <<a href="mailto:gbarr@pobox.com">gbarr@pobox.com</a>>. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.</p> <table border="0" width="100%" cellspacing="0" cellpadding="3"> <tr><td class="block" style="background-color: #cccccc" valign="middle"> <big><strong><span class="block"> List::Util - A selection of general-utility list subroutines</span></strong></big> </td></tr> </table> </body> </html>
Ms-Dos/Windows
Unix
Write backup
jsp File Browser version 1.2 by
www.vonloesch.de