Server IP : 103.119.228.120 / Your IP : 18.221.102.0 Web Server : Apache System : Linux v8.techscape8.com 3.10.0-1160.119.1.el7.tuxcare.els2.x86_64 #1 SMP Mon Jul 15 12:09:18 UTC 2024 x86_64 User : nobody ( 99) PHP Version : 5.6.40 Disable Function : shell_exec,symlink,system,exec,proc_get_status,proc_nice,proc_terminate,define_syslog_variables,syslog,openlog,closelog,escapeshellcmd,passthru,ocinum cols,ini_alter,leak,listen,chgrp,apache_note,apache_setenv,debugger_on,debugger_off,ftp_exec,dl,dll,myshellexec,proc_open,socket_bind,proc_close,escapeshellarg,parse_ini_filepopen,fpassthru,exec,passthru,escapeshellarg,escapeshellcmd,proc_close,proc_open,ini_alter,popen,show_source,proc_nice,proc_terminate,proc_get_status,proc_close,pfsockopen,leak,apache_child_terminate,posix_kill,posix_mkfifo,posix_setpgid,posix_setsid,posix_setuid,dl,symlink,shell_exec,system,dl,passthru,escapeshellarg,escapeshellcmd,myshellexec,c99_buff_prepare,c99_sess_put,fpassthru,getdisfunc,fx29exec,fx29exec2,is_windows,disp_freespace,fx29sh_getupdate,fx29_buff_prepare,fx29_sess_put,fx29shexit,fx29fsearch,fx29ftpbrutecheck,fx29sh_tools,fx29sh_about,milw0rm,imagez,sh_name,myshellexec,checkproxyhost,dosyayicek,c99_buff_prepare,c99_sess_put,c99getsource,c99sh_getupdate,c99fsearch,c99shexit,view_perms,posix_getpwuid,posix_getgrgid,posix_kill,parse_perms,parsesort,view_perms_color,set_encoder_input,ls_setcheckboxall,ls_reverse_all,rsg_read,rsg_glob,selfURL,dispsecinfo,unix2DosTime,addFile,system,get_users,view_size,DirFiles,DirFilesWide,DirPrintHTMLHeaders,GetFilesTotal,GetTitles,GetTimeTotal,GetMatchesCount,GetFileMatchesCount,GetResultFiles,fs_copy_dir,fs_copy_obj,fs_move_dir,fs_move_obj,fs_rmdir,SearchText,getmicrotime MySQL : ON | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /usr/local/ssl/local/ssl/local/ssl/local/ssl/local/ssl/local/share/man/man3/ |
Upload File : |
.\" Automatically generated by Pod::Man 2.27 (Pod::Simple 3.28) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is turned on, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{ . if \nF \{ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. . \" fudge factors for nroff and troff .if n \{\ . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] \fP .\} .if t \{\ . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff .if n \{\ . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} .if t \{\ . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' .ds 8 \h'\*(#H'\(*b\h'-\*(#H' .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] .ds ae a\h'-(\w'a'u*4/10)'e .ds Ae A\h'-(\w'A'u*4/10)'E . \" corrections for vroff .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' . \" for low resolution devices (crt and lpr) .if \n(.H>23 .if \n(.V>19 \ \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} .rm #[ #] #H #V #F C .\" ======================================================================== .\" .IX Title "List::MoreUtils 3" .TH List::MoreUtils 3 "2016-07-06" "perl v5.16.3" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" List::MoreUtils \- Provide the stuff missing in List::Util .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 1 \& # import specific functions \& \& use List::MoreUtils qw(any uniq); \& \& if ( any { /foo/ } uniq @has_duplicates ) { \& # do stuff \& } \& \& # import everything \& \& use List::MoreUtils \*(Aq:all\*(Aq; \& \& # import by API \& \& # has "original" any/all/none/notall behavior \& use List::MoreUtils \*(Aq:like_0.22\*(Aq; \& # 0.22 + bsearch \& use List::MoreUtils \*(Aq:like_0.24\*(Aq; \& # has "simplified" any/all/none/notall behavior + (n)sort_by \& use List::MoreUtils \*(Aq:like_0.33\*(Aq; .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" \&\fBList::MoreUtils\fR provides some trivial but commonly needed functionality on lists which is not going to go into List::Util. .PP All of the below functions are implementable in only a couple of lines of Perl code. Using the functions from this module however should give slightly better performance as everything is implemented in C. The pure-Perl implementation of these functions only serves as a fallback in case the C portions of this module couldn't be compiled on this machine. .SH "EXPORTS" .IX Header "EXPORTS" .SS "Default behavior" .IX Subsection "Default behavior" Nothing by default. To import all of this module's symbols use the \f(CW\*(C`:all\*(C'\fR tag. Otherwise functions can be imported by name as usual: .PP .Vb 1 \& use List::MoreUtils \*(Aq:all\*(Aq; \& \& use List::MoreUtils qw{ any firstidx }; .Ve .PP Because historical changes to the \s-1API\s0 might make upgrading List::MoreUtils difficult for some projects, the legacy \s-1API\s0 is available via special import tags. .SS "Like version 0.22 (last release with original \s-1API\s0)" .IX Subsection "Like version 0.22 (last release with original API)" This \s-1API\s0 was available from 2006 to 2009, returning undef for empty lists on \&\f(CW\*(C`all\*(C'\fR/\f(CW\*(C`any\*(C'\fR/\f(CW\*(C`none\*(C'\fR/\f(CW\*(C`notall\*(C'\fR: .PP .Vb 1 \& use List::MoreUtils \*(Aq:like_0.22\*(Aq; .Ve .PP This import tag will import all functions available as of version 0.22. However, it will import \f(CW\*(C`any_u\*(C'\fR as \f(CW\*(C`any\*(C'\fR, \f(CW\*(C`all_u\*(C'\fR as \f(CW\*(C`all\*(C'\fR, \f(CW\*(C`none_u\*(C'\fR as \&\f(CW\*(C`none\*(C'\fR, and \f(CW\*(C`notall_u\*(C'\fR as \f(CW\*(C`notall\*(C'\fR. .SS "Like version 0.24 (first incompatible change)" .IX Subsection "Like version 0.24 (first incompatible change)" This \s-1API\s0 was available from 2010 to 2011. It changed the return value of \f(CW\*(C`none\*(C'\fR and added the \f(CW\*(C`bsearch\*(C'\fR function. .PP .Vb 1 \& use List::MoreUtils \*(Aq:like_0.24\*(Aq; .Ve .PP This import tag will import all functions available as of version 0.24. However it will import \f(CW\*(C`any_u\*(C'\fR as \f(CW\*(C`any\*(C'\fR, \f(CW\*(C`all_u\*(C'\fR as \f(CW\*(C`all\*(C'\fR, and \&\f(CW\*(C`notall_u\*(C'\fR as \f(CW\*(C`notall\*(C'\fR. It will import \f(CW\*(C`none\*(C'\fR as described in the documentation below (true for empty list). .SS "Like version 0.33 (second incompatible change)" .IX Subsection "Like version 0.33 (second incompatible change)" This \s-1API\s0 was available from 2011 to 2014. It is widely used in several \s-1CPAN\s0 modules and thus it's closest to the current \s-1API. \s0 It changed the return values of \f(CW\*(C`any\*(C'\fR, \f(CW\*(C`all\*(C'\fR, and \f(CW\*(C`notall\*(C'\fR. It added the \f(CW\*(C`sort_by\*(C'\fR and \f(CW\*(C`nsort_by\*(C'\fR functions and the \f(CW\*(C`distinct\*(C'\fR alias for \f(CW\*(C`uniq\*(C'\fR. It omitted \f(CW\*(C`bsearch\*(C'\fR. .PP .Vb 1 \& use List::MoreUtils \*(Aq:like_0.33\*(Aq; .Ve .PP This import tag will import all functions available as of version 0.33. Note: it will not import \f(CW\*(C`bsearch\*(C'\fR for consistency with the 0.33 \s-1API.\s0 .SH "FUNCTIONS" .IX Header "FUNCTIONS" .SS "Junctions" .IX Subsection "Junctions" \fI\fITreatment of an empty list\fI\fR .IX Subsection "Treatment of an empty list" .PP There are two schools of thought for how to evaluate a junction on an empty list: .IP "\(bu" 4 Reduction to an identity (boolean) .IP "\(bu" 4 Result is undefined (three-valued) .PP In the first case, the result of the junction applied to the empty list is determined by a mathematical reduction to an identity depending on whether the underlying comparison is \*(L"or\*(R" or \*(L"and\*(R". Conceptually: .PP .Vb 5 \& "any are true" "all are true" \& \-\-\-\-\-\-\-\-\-\-\-\-\-\- \-\-\-\-\-\-\-\-\-\-\-\-\-\- \& 2 elements: A || B || 0 A && B && 1 \& 1 element: A || 0 A && 1 \& 0 elements: 0 1 .Ve .PP In the second case, three-value logic is desired, in which a junction applied to an empty list returns \f(CW\*(C`undef\*(C'\fR rather than true or false .PP Junctions with a \f(CW\*(C`_u\*(C'\fR suffix implement three-valued logic. Those without are boolean. .PP \fIall \s-1BLOCK LIST\s0\fR .IX Subsection "all BLOCK LIST" .PP \fIall_u \s-1BLOCK LIST\s0\fR .IX Subsection "all_u BLOCK LIST" .PP Returns a true value if all items in \s-1LIST\s0 meet the criterion given through \&\s-1BLOCK.\s0 Sets \f(CW$_\fR for each item in \s-1LIST\s0 in turn: .PP .Vb 2 \& print "All values are non\-negative" \& if all { $_ >= 0 } ($x, $y, $z); .Ve .PP For an empty \s-1LIST, \s0\f(CW\*(C`all\*(C'\fR returns true (i.e. no values failed the condition) and \f(CW\*(C`all_u\*(C'\fR returns \f(CW\*(C`undef\*(C'\fR. .PP Thus, \f(CW\*(C`all_u(@list)\*(C'\fR is equivalent to \f(CW\*(C`@list ? all(@list) : undef\*(C'\fR. .PP \&\fBNote\fR: because Perl treats \f(CW\*(C`undef\*(C'\fR as false, you must check the return value of \f(CW\*(C`all_u\*(C'\fR with \f(CW\*(C`defined\*(C'\fR or you will get the opposite result of what you expect. .PP \fIany \s-1BLOCK LIST\s0\fR .IX Subsection "any BLOCK LIST" .PP \fIany_u \s-1BLOCK LIST\s0\fR .IX Subsection "any_u BLOCK LIST" .PP Returns a true value if any item in \s-1LIST\s0 meets the criterion given through \&\s-1BLOCK.\s0 Sets \f(CW$_\fR for each item in \s-1LIST\s0 in turn: .PP .Vb 2 \& print "At least one non\-negative value" \& if any { $_ >= 0 } ($x, $y, $z); .Ve .PP For an empty \s-1LIST, \s0\f(CW\*(C`any\*(C'\fR returns false and \f(CW\*(C`any_u\*(C'\fR returns \f(CW\*(C`undef\*(C'\fR. .PP Thus, \f(CW\*(C`any_u(@list)\*(C'\fR is equivalent to \f(CW\*(C`@list ? any(@list) : undef\*(C'\fR. .PP \fInone \s-1BLOCK LIST\s0\fR .IX Subsection "none BLOCK LIST" .PP \fInone_u \s-1BLOCK LIST\s0\fR .IX Subsection "none_u BLOCK LIST" .PP Logically the negation of \f(CW\*(C`any\*(C'\fR. Returns a true value if no item in \s-1LIST\s0 meets the criterion given through \s-1BLOCK.\s0 Sets \f(CW$_\fR for each item in \s-1LIST\s0 in turn: .PP .Vb 2 \& print "No non\-negative values" \& if none { $_ >= 0 } ($x, $y, $z); .Ve .PP For an empty \s-1LIST, \s0\f(CW\*(C`none\*(C'\fR returns true (i.e. no values failed the condition) and \f(CW\*(C`none_u\*(C'\fR returns \f(CW\*(C`undef\*(C'\fR. .PP Thus, \f(CW\*(C`none_u(@list)\*(C'\fR is equivalent to \f(CW\*(C`@list ? none(@list) : undef\*(C'\fR. .PP \&\fBNote\fR: because Perl treats \f(CW\*(C`undef\*(C'\fR as false, you must check the return value of \f(CW\*(C`none_u\*(C'\fR with \f(CW\*(C`defined\*(C'\fR or you will get the opposite result of what you expect. .PP \fInotall \s-1BLOCK LIST\s0\fR .IX Subsection "notall BLOCK LIST" .PP \fInotall_u \s-1BLOCK LIST\s0\fR .IX Subsection "notall_u BLOCK LIST" .PP Logically the negation of \f(CW\*(C`all\*(C'\fR. Returns a true value if not all items in \s-1LIST\s0 meet the criterion given through \s-1BLOCK.\s0 Sets \f(CW$_\fR for each item in \s-1LIST\s0 in turn: .PP .Vb 2 \& print "Not all values are non\-negative" \& if notall { $_ >= 0 } ($x, $y, $z); .Ve .PP For an empty \s-1LIST, \s0\f(CW\*(C`notall\*(C'\fR returns false and \f(CW\*(C`notall_u\*(C'\fR returns \f(CW\*(C`undef\*(C'\fR. .PP Thus, \f(CW\*(C`notall_u(@list)\*(C'\fR is equivalent to \f(CW\*(C`@list ? notall(@list) : undef\*(C'\fR. .PP \fIone \s-1BLOCK LIST\s0\fR .IX Subsection "one BLOCK LIST" .PP \fIone_u \s-1BLOCK LIST\s0\fR .IX Subsection "one_u BLOCK LIST" .PP Returns a true value if precisely one item in \s-1LIST\s0 meets the criterion given through \s-1BLOCK.\s0 Sets \f(CW$_\fR for each item in \s-1LIST\s0 in turn: .PP .Vb 2 \& print "Precisely one value defined" \& if one { defined($_) } @list; .Ve .PP Returns false otherwise. .PP For an empty \s-1LIST, \s0\f(CW\*(C`one\*(C'\fR returns false and \f(CW\*(C`one_u\*(C'\fR returns \f(CW\*(C`undef\*(C'\fR. .PP The expression \f(CW\*(C`one BLOCK LIST\*(C'\fR is almost equivalent to \&\f(CW\*(C`1 == true BLOCK LIST\*(C'\fR, except for short-cutting. Evaluation of \s-1BLOCK\s0 will immediately stop at the second true value. .SS "Transformation" .IX Subsection "Transformation" \fIapply \s-1BLOCK LIST\s0\fR .IX Subsection "apply BLOCK LIST" .PP Applies \s-1BLOCK\s0 to each item in \s-1LIST\s0 and returns a list of the values after \s-1BLOCK\s0 has been applied. In scalar context, the last element is returned. This function is similar to \f(CW\*(C`map\*(C'\fR but will not modify the elements of the input list: .PP .Vb 7 \& my @list = (1 .. 4); \& my @mult = apply { $_ *= 2 } @list; \& print "\e@list = @list\en"; \& print "\e@mult = @mult\en"; \& _\|_END_\|_ \& @list = 1 2 3 4 \& @mult = 2 4 6 8 .Ve .PP Think of it as syntactic sugar for .PP .Vb 1 \& for (my @mult = @list) { $_ *= 2 } .Ve .PP \fIinsert_after \s-1BLOCK VALUE LIST\s0\fR .IX Subsection "insert_after BLOCK VALUE LIST" .PP Inserts \s-1VALUE\s0 after the first item in \s-1LIST\s0 for which the criterion in \s-1BLOCK\s0 is true. Sets \f(CW$_\fR for each item in \s-1LIST\s0 in turn. .PP .Vb 5 \& my @list = qw/This is a list/; \& insert_after { $_ eq "a" } "longer" => @list; \& print "@list"; \& _\|_END_\|_ \& This is a longer list .Ve .PP \fIinsert_after_string \s-1STRING VALUE LIST\s0\fR .IX Subsection "insert_after_string STRING VALUE LIST" .PP Inserts \s-1VALUE\s0 after the first item in \s-1LIST\s0 which is equal to \s-1STRING. \s0 .PP .Vb 5 \& my @list = qw/This is a list/; \& insert_after_string "a", "longer" => @list; \& print "@list"; \& _\|_END_\|_ \& This is a longer list .Ve .PP \fIpairwise \s-1BLOCK ARRAY1 ARRAY2\s0\fR .IX Subsection "pairwise BLOCK ARRAY1 ARRAY2" .PP Evaluates \s-1BLOCK\s0 for each pair of elements in \s-1ARRAY1\s0 and \s-1ARRAY2\s0 and returns a new list consisting of \s-1BLOCK\s0's return values. The two elements are set to \f(CW$a\fR and \f(CW$b\fR. Note that those two are aliases to the original value so changing them will modify the input arrays. .PP .Vb 3 \& @a = (1 .. 5); \& @b = (11 .. 15); \& @x = pairwise { $a + $b } @a, @b; # returns 12, 14, 16, 18, 20 \& \& # mesh with pairwise \& @a = qw/a b c/; \& @b = qw/1 2 3/; \& @x = pairwise { ($a, $b) } @a, @b; # returns a, 1, b, 2, c, 3 .Ve .PP \fImesh \s-1ARRAY1 ARRAY2\s0 [ \s-1ARRAY3 ... \s0]\fR .IX Subsection "mesh ARRAY1 ARRAY2 [ ARRAY3 ... ]" .PP \fIzip \s-1ARRAY1 ARRAY2\s0 [ \s-1ARRAY3 ... \s0]\fR .IX Subsection "zip ARRAY1 ARRAY2 [ ARRAY3 ... ]" .PP Returns a list consisting of the first elements of each array, then the second, then the third, etc, until all arrays are exhausted. .PP Examples: .PP .Vb 3 \& @x = qw/a b c d/; \& @y = qw/1 2 3 4/; \& @z = mesh @x, @y; # returns a, 1, b, 2, c, 3, d, 4 \& \& @a = (\*(Aqx\*(Aq); \& @b = (\*(Aq1\*(Aq, \*(Aq2\*(Aq); \& @c = qw/zip zap zot/; \& @d = mesh @a, @b, @c; # x, 1, zip, undef, 2, zap, undef, undef, zot .Ve .PP \&\f(CW\*(C`zip\*(C'\fR is an alias for \f(CW\*(C`mesh\*(C'\fR. .PP \fIuniq \s-1LIST\s0\fR .IX Subsection "uniq LIST" .PP \fIdistinct \s-1LIST\s0\fR .IX Subsection "distinct LIST" .PP Returns a new list by stripping duplicate values in \s-1LIST\s0 by comparing the values as hash keys, except that undef is considered separate from ''. The order of elements in the returned list is the same as in \s-1LIST.\s0 In scalar context, returns the number of unique elements in \s-1LIST.\s0 .PP .Vb 8 \& my @x = uniq 1, 1, 2, 2, 3, 5, 3, 4; # returns 1 2 3 5 4 \& my $x = uniq 1, 1, 2, 2, 3, 5, 3, 4; # returns 5 \& # returns "Mike", "Michael", "Richard", "Rick" \& my @n = distinct "Mike", "Michael", "Richard", "Rick", "Michael", "Rick" \& # returns \*(Aq\*(Aq, \*(AqS1\*(Aq, A5\*(Aq and complains about "Use of uninitialized value" \& my @s = distinct \*(Aq\*(Aq, undef, \*(AqS1\*(Aq, \*(AqA5\*(Aq \& # returns undef, \*(AqS1\*(Aq, A5\*(Aq and complains about "Use of uninitialized value" \& my @w = uniq undef, \*(Aq\*(Aq, \*(AqS1\*(Aq, \*(AqA5\*(Aq .Ve .PP \&\f(CW\*(C`distinct\*(C'\fR is an alias for \f(CW\*(C`uniq\*(C'\fR. .PP \&\fBRT#49800\fR can be used to give feedback about this behavior. .PP \fIsingleton\fR .IX Subsection "singleton" .PP Returns a new list by stripping values in \s-1LIST\s0 occurring more than once by comparing the values as hash keys, except that undef is considered separate from ''. The order of elements in the returned list is the same as in \s-1LIST.\s0 In scalar context, returns the number of elements occurring only once in \s-1LIST.\s0 .PP .Vb 1 \& my @x = singleton 1,1,2,2,3,4,5 # returns 3 4 5 .Ve .SS "Partitioning" .IX Subsection "Partitioning" \fIafter \s-1BLOCK LIST\s0\fR .IX Subsection "after BLOCK LIST" .PP Returns a list of the values of \s-1LIST\s0 after (and not including) the point where \s-1BLOCK\s0 returns a true value. Sets \f(CW$_\fR for each element in \s-1LIST\s0 in turn. .PP .Vb 1 \& @x = after { $_ % 5 == 0 } (1..9); # returns 6, 7, 8, 9 .Ve .PP \fIafter_incl \s-1BLOCK LIST\s0\fR .IX Subsection "after_incl BLOCK LIST" .PP Same as \f(CW\*(C`after\*(C'\fR but also includes the element for which \s-1BLOCK\s0 is true. .PP \fIbefore \s-1BLOCK LIST\s0\fR .IX Subsection "before BLOCK LIST" .PP Returns a list of values of \s-1LIST\s0 up to (and not including) the point where \s-1BLOCK\s0 returns a true value. Sets \f(CW$_\fR for each element in \s-1LIST\s0 in turn. .PP \fIbefore_incl \s-1BLOCK LIST\s0\fR .IX Subsection "before_incl BLOCK LIST" .PP Same as \f(CW\*(C`before\*(C'\fR but also includes the element for which \s-1BLOCK\s0 is true. .PP \fIpart \s-1BLOCK LIST\s0\fR .IX Subsection "part BLOCK LIST" .PP Partitions \s-1LIST\s0 based on the return value of \s-1BLOCK\s0 which denotes into which partition the current value is put. .PP Returns a list of the partitions thusly created. Each partition created is a reference to an array. .PP .Vb 2 \& my $i = 0; \& my @part = part { $i++ % 2 } 1 .. 8; # returns [1, 3, 5, 7], [2, 4, 6, 8] .Ve .PP You can have a sparse list of partitions as well where non-set partitions will be undef: .PP .Vb 1 \& my @part = part { 2 } 1 .. 10; # returns undef, undef, [ 1 .. 10 ] .Ve .PP Be careful with negative values, though: .PP .Vb 3 \& my @part = part { \-1 } 1 .. 10; \& _\|_END_\|_ \& Modification of non\-creatable array value attempted, subscript \-1 ... .Ve .PP Negative values are only ok when they refer to a partition previously created: .PP .Vb 3 \& my @idx = ( 0, 1, \-1 ); \& my $i = 0; \& my @part = part { $idx[$++ % 3] } 1 .. 8; # [1, 4, 7], [2, 3, 5, 6, 8] .Ve .SS "Iteration" .IX Subsection "Iteration" \fIeach_array \s-1ARRAY1 ARRAY2 ...\s0\fR .IX Subsection "each_array ARRAY1 ARRAY2 ..." .PP Creates an array iterator to return the elements of the list of arrays \s-1ARRAY1, ARRAY2\s0 throughout ARRAYn in turn. That is, the first time it is called, it returns the first element of each array. The next time, it returns the second elements. And so on, until all elements are exhausted. .PP This is useful for looping over more than one array at once: .PP .Vb 2 \& my $ea = each_array(@a, @b, @c); \& while ( my ($a, $b, $c) = $ea\->() ) { .... } .Ve .PP The iterator returns the empty list when it reached the end of all arrays. .PP If the iterator is passed an argument of '\f(CW\*(C`index\*(C'\fR', then it returns the index of the last fetched set of values, as a scalar. .PP \fIeach_arrayref \s-1LIST\s0\fR .IX Subsection "each_arrayref LIST" .PP Like each_array, but the arguments are references to arrays, not the plain arrays. .PP \fInatatime \s-1EXPR, LIST\s0\fR .IX Subsection "natatime EXPR, LIST" .PP Creates an array iterator, for looping over an array in chunks of \&\f(CW$n\fR items at a time. (n at a time, get it?). An example is probably a better explanation than I could give in words. .PP Example: .PP .Vb 6 \& my @x = (\*(Aqa\*(Aq .. \*(Aqg\*(Aq); \& my $it = natatime 3, @x; \& while (my @vals = $it\->()) \& { \& print "@vals\en"; \& } .Ve .PP This prints .PP .Vb 3 \& a b c \& d e f \& g .Ve .SS "Searching" .IX Subsection "Searching" \fIbsearch \s-1BLOCK LIST\s0\fR .IX Subsection "bsearch BLOCK LIST" .PP Performs a binary search on \s-1LIST\s0 which must be a sorted list of values. \s-1BLOCK\s0 must return a negative value if the current element (stored in \f(CW$_\fR) is smaller, a positive value if it is bigger and zero if it matches. .PP Returns a boolean value in scalar context. In list context, it returns the element if it was found, otherwise the empty list. .PP \fIbsearchidx \s-1BLOCK LIST\s0\fR .IX Subsection "bsearchidx BLOCK LIST" .PP \fIbsearch_index \s-1BLOCK LIST\s0\fR .IX Subsection "bsearch_index BLOCK LIST" .PP Performs a binary search on \s-1LIST\s0 which must be a sorted list of values. \s-1BLOCK\s0 must return a negative value if the current element (stored in \f(CW$_\fR) is smaller, a positive value if it is bigger and zero if it matches. .PP Returns the index of found element, otherwise \f(CW\*(C`\-1\*(C'\fR. .PP \&\f(CW\*(C`bsearch_index\*(C'\fR is an alias for \f(CW\*(C`bsearchidx\*(C'\fR. .PP \fIfirstval \s-1BLOCK LIST\s0\fR .IX Subsection "firstval BLOCK LIST" .PP \fIfirst_value \s-1BLOCK LIST\s0\fR .IX Subsection "first_value BLOCK LIST" .PP Returns the first element in \s-1LIST\s0 for which \s-1BLOCK\s0 evaluates to true. Each element of \s-1LIST\s0 is set to \f(CW$_\fR in turn. Returns \f(CW\*(C`undef\*(C'\fR if no such element has been found. .PP \&\f(CW\*(C`first_value\*(C'\fR is an alias for \f(CW\*(C`firstval\*(C'\fR. .PP \fIonlyval \s-1BLOCK LIST\s0\fR .IX Subsection "onlyval BLOCK LIST" .PP \fIonly_value \s-1BLOCK LIST\s0\fR .IX Subsection "only_value BLOCK LIST" .PP Returns the only element in \s-1LIST\s0 for which \s-1BLOCK\s0 evaluates to true. Sets \&\f(CW$_\fR for each item in \s-1LIST\s0 in turn. Returns \f(CW\*(C`undef\*(C'\fR if no such element has been found. .PP \&\f(CW\*(C`only_value\*(C'\fR is an alias for \f(CW\*(C`onlyval\*(C'\fR. .PP \fIlastval \s-1BLOCK LIST\s0\fR .IX Subsection "lastval BLOCK LIST" .PP \fIlast_value \s-1BLOCK LIST\s0\fR .IX Subsection "last_value BLOCK LIST" .PP Returns the last value in \s-1LIST\s0 for which \s-1BLOCK\s0 evaluates to true. Each element of \s-1LIST\s0 is set to \f(CW$_\fR in turn. Returns \f(CW\*(C`undef\*(C'\fR if no such element has been found. .PP \&\f(CW\*(C`last_value\*(C'\fR is an alias for \f(CW\*(C`lastval\*(C'\fR. .PP \fIfirstres \s-1BLOCK LIST\s0\fR .IX Subsection "firstres BLOCK LIST" .PP \fIfirst_result \s-1BLOCK LIST\s0\fR .IX Subsection "first_result BLOCK LIST" .PP Returns the result of \s-1BLOCK\s0 for the first element in \s-1LIST\s0 for which \s-1BLOCK\s0 evaluates to true. Each element of \s-1LIST\s0 is set to \f(CW$_\fR in turn. Returns \&\f(CW\*(C`undef\*(C'\fR if no such element has been found. .PP \&\f(CW\*(C`first_result\*(C'\fR is an alias for \f(CW\*(C`firstres\*(C'\fR. .PP \fIonlyres \s-1BLOCK LIST\s0\fR .IX Subsection "onlyres BLOCK LIST" .PP \fIonly_result \s-1BLOCK LIST\s0\fR .IX Subsection "only_result BLOCK LIST" .PP Returns the result of \s-1BLOCK\s0 for the first element in \s-1LIST\s0 for which \s-1BLOCK\s0 evaluates to true. Sets \f(CW$_\fR for each item in \s-1LIST\s0 in turn. Returns \&\f(CW\*(C`undef\*(C'\fR if no such element has been found. .PP \&\f(CW\*(C`only_result\*(C'\fR is an alias for \f(CW\*(C`onlyres\*(C'\fR. .PP \fIlastres \s-1BLOCK LIST\s0\fR .IX Subsection "lastres BLOCK LIST" .PP \fIlast_result \s-1BLOCK LIST\s0\fR .IX Subsection "last_result BLOCK LIST" .PP Returns the result of \s-1BLOCK\s0 for the last element in \s-1LIST\s0 for which \s-1BLOCK\s0 evaluates to true. Each element of \s-1LIST\s0 is set to \f(CW$_\fR in turn. Returns \&\f(CW\*(C`undef\*(C'\fR if no such element has been found. .PP \&\f(CW\*(C`last_result\*(C'\fR is an alias for \f(CW\*(C`lastres\*(C'\fR. .PP \fIindexes \s-1BLOCK LIST\s0\fR .IX Subsection "indexes BLOCK LIST" .PP Evaluates \s-1BLOCK\s0 for each element in \s-1LIST \s0(assigned to \f(CW$_\fR) and returns a list of the indices of those elements for which \s-1BLOCK\s0 returned a true value. This is just like \f(CW\*(C`grep\*(C'\fR only that it returns indices instead of values: .PP .Vb 1 \& @x = indexes { $_ % 2 == 0 } (1..10); # returns 1, 3, 5, 7, 9 .Ve .PP \fIfirstidx \s-1BLOCK LIST\s0\fR .IX Subsection "firstidx BLOCK LIST" .PP \fIfirst_index \s-1BLOCK LIST\s0\fR .IX Subsection "first_index BLOCK LIST" .PP Returns the index of the first element in \s-1LIST\s0 for which the criterion in \s-1BLOCK\s0 is true. Sets \f(CW$_\fR for each item in \s-1LIST\s0 in turn: .PP .Vb 4 \& my @list = (1, 4, 3, 2, 4, 6); \& printf "item with index %i in list is 4", firstidx { $_ == 4 } @list; \& _\|_END_\|_ \& item with index 1 in list is 4 .Ve .PP Returns \f(CW\*(C`\-1\*(C'\fR if no such item could be found. .PP \&\f(CW\*(C`first_index\*(C'\fR is an alias for \f(CW\*(C`firstidx\*(C'\fR. .PP \fIonlyidx \s-1BLOCK LIST\s0\fR .IX Subsection "onlyidx BLOCK LIST" .PP \fIonly_index \s-1BLOCK LIST\s0\fR .IX Subsection "only_index BLOCK LIST" .PP Returns the index of the only element in \s-1LIST\s0 for which the criterion in \s-1BLOCK\s0 is true. Sets \f(CW$_\fR for each item in \s-1LIST\s0 in turn: .PP .Vb 4 \& my @list = (1, 3, 4, 3, 2, 4); \& printf "uniqe index of item 2 in list is %i", onlyidx { $_ == 2 } @list; \& _\|_END_\|_ \& unique index of item 2 in list is 4 .Ve .PP Returns \f(CW\*(C`\-1\*(C'\fR if either no such item or more than one of these has been found. .PP \&\f(CW\*(C`only_index\*(C'\fR is an alias for \f(CW\*(C`onlyidx\*(C'\fR. .PP \fIlastidx \s-1BLOCK LIST\s0\fR .IX Subsection "lastidx BLOCK LIST" .PP \fIlast_index \s-1BLOCK LIST\s0\fR .IX Subsection "last_index BLOCK LIST" .PP Returns the index of the last element in \s-1LIST\s0 for which the criterion in \s-1BLOCK\s0 is true. Sets \f(CW$_\fR for each item in \s-1LIST\s0 in turn: .PP .Vb 4 \& my @list = (1, 4, 3, 2, 4, 6); \& printf "item with index %i in list is 4", lastidx { $_ == 4 } @list; \& _\|_END_\|_ \& item with index 4 in list is 4 .Ve .PP Returns \f(CW\*(C`\-1\*(C'\fR if no such item could be found. .PP \&\f(CW\*(C`last_index\*(C'\fR is an alias for \f(CW\*(C`lastidx\*(C'\fR. .SS "Sorting" .IX Subsection "Sorting" \fIsort_by \s-1BLOCK LIST\s0\fR .IX Subsection "sort_by BLOCK LIST" .PP Returns the list of values sorted according to the string values returned by the \&\s-1KEYFUNC\s0 block or function. A typical use of this may be to sort objects according to the string value of some accessor, such as .PP .Vb 1 \& sort_by { $_\->name } @people .Ve .PP The key function is called in scalar context, being passed each value in turn as both \f(CW$_\fR and the only argument in the parameters, \f(CW@_\fR. The values are then sorted according to string comparisons on the values returned. This is equivalent to .PP .Vb 1 \& sort { $a\->name cmp $b\->name } @people .Ve .PP except that it guarantees the name accessor will be executed only once per value. One interesting use-case is to sort strings which may have numbers embedded in them \&\*(L"naturally\*(R", rather than lexically. .PP .Vb 1 \& sort_by { s/(\ed+)/sprintf "%09d", $1/eg; $_ } @strings .Ve .PP This sorts strings by generating sort keys which zero-pad the embedded numbers to some level (9 digits in this case), helping to ensure the lexical sort puts them in the correct order. .PP \fInsort_by \s-1BLOCK LIST\s0\fR .IX Subsection "nsort_by BLOCK LIST" .PP Similar to sort_by but compares its key values numerically. .SS "Counting and calculation" .IX Subsection "Counting and calculation" \fItrue \s-1BLOCK LIST\s0\fR .IX Subsection "true BLOCK LIST" .PP Counts the number of elements in \s-1LIST\s0 for which the criterion in \s-1BLOCK\s0 is true. Sets \f(CW$_\fR for each item in \s-1LIST\s0 in turn: .PP .Vb 1 \& printf "%i item(s) are defined", true { defined($_) } @list; .Ve .PP \fIfalse \s-1BLOCK LIST\s0\fR .IX Subsection "false BLOCK LIST" .PP Counts the number of elements in \s-1LIST\s0 for which the criterion in \s-1BLOCK\s0 is false. Sets \f(CW$_\fR for each item in \s-1LIST\s0 in turn: .PP .Vb 1 \& printf "%i item(s) are not defined", false { defined($_) } @list; .Ve .PP \fIminmax \s-1LIST\s0\fR .IX Subsection "minmax LIST" .PP Calculates the minimum and maximum of \s-1LIST\s0 and returns a two element list with the first element being the minimum and the second the maximum. Returns the empty list if \s-1LIST\s0 was empty. .PP The \f(CW\*(C`minmax\*(C'\fR algorithm differs from a naive iteration over the list where each element is compared to two values being the so far calculated min and max value in that it only requires 3n/2 \- 2 comparisons. Thus it is the most efficient possible algorithm. .PP However, the Perl implementation of it has some overhead simply due to the fact that there are more lines of Perl code involved. Therefore, \s-1LIST\s0 needs to be fairly big in order for \f(CW\*(C`minmax\*(C'\fR to win over a naive implementation. This limitation does not apply to the \s-1XS\s0 version. .SH "ENVIRONMENT" .IX Header "ENVIRONMENT" When \f(CW\*(C`LIST_MOREUTILS_PP\*(C'\fR is set, the module will always use the pure-Perl implementation and not the \s-1XS\s0 one. This environment variable is really just there for the test-suite to force testing the Perl implementation, and possibly for reporting of bugs. I don't see any reason to use it in a production environment. .SH "MAINTENANCE" .IX Header "MAINTENANCE" The maintenance goal is to preserve the documented semantics of the \s-1API\s0; bug fixes that bring actual behavior in line with semantics are allowed. New \s-1API\s0 functions may be added over time. If a backwards incompatible change is unavoidable, we will attempt to provide support for the legacy \&\s-1API\s0 using the same export tag mechanism currently in place. .PP This module attempts to use few non-core dependencies. Non-core configuration and testing modules will be bundled when reasonable; run-time dependencies will be added only if they deliver substantial benefit. .SH "CONTRIBUTING" .IX Header "CONTRIBUTING" While contributions are appreciated, a contribution should not cause more effort for the maintainer than the contribution itself saves (see Open Source Contribution Etiquette <http://tirania.org/blog/archive/2010/Dec-31.html>). .PP To get more familiar where help could be needed \- see List::MoreUtils::Contributing. .SH "BUGS" .IX Header "BUGS" There is a problem with a bug in 5.6.x perls. It is a syntax error to write things like: .PP .Vb 1 \& my @x = apply { s/foo/bar/ } qw{ foo bar baz }; .Ve .PP It has to be written as either .PP .Vb 1 \& my @x = apply { s/foo/bar/ } \*(Aqfoo\*(Aq, \*(Aqbar\*(Aq, \*(Aqbaz\*(Aq; .Ve .PP or .PP .Vb 1 \& my @x = apply { s/foo/bar/ } my @dummy = qw/foo bar baz/; .Ve .PP Perl 5.5.x and Perl 5.8.x don't suffer from this limitation. .PP If you have a functionality that you could imagine being in this module, please drop me a line. This module's policy will be less strict than List::Util's when it comes to additions as it isn't a core module. .PP When you report bugs, it would be nice if you could additionally give me the output of your program with the environment variable \f(CW\*(C`LIST_MOREUTILS_PP\*(C'\fR set to a true value. That way I know where to look for the problem (in \s-1XS,\s0 pure-Perl or possibly both). .SH "SUPPORT" .IX Header "SUPPORT" Bugs should always be submitted via the \s-1CPAN\s0 bug tracker. .PP You can find documentation for this module with the perldoc command. .PP .Vb 1 \& perldoc List::MoreUtils .Ve .PP You can also look for information at: .IP "\(bu" 4 \&\s-1RT: CPAN\s0's request tracker .Sp <https://rt.cpan.org/Dist/Display.html?Name=List\-MoreUtils> .IP "\(bu" 4 AnnoCPAN: Annotated \s-1CPAN\s0 documentation .Sp <http://annocpan.org/dist/List\-MoreUtils> .IP "\(bu" 4 \&\s-1CPAN\s0 Ratings .Sp <http://cpanratings.perl.org/dist/List\-MoreUtils> .IP "\(bu" 4 MetaCPAN .Sp <https://metacpan.org/release/List\-MoreUtils> .IP "\(bu" 4 \&\s-1CPAN\s0 Search .Sp <http://search.cpan.org/dist/List\-MoreUtils/> .IP "\(bu" 4 Git Repository .Sp <https://github.com/perl5\-utils/List\-MoreUtils> .SS "Where can I go for help?" .IX Subsection "Where can I go for help?" If you have a bug report, a patch or a suggestion, please open a new report ticket at \s-1CPAN \s0(but please check previous reports first in case your issue has already been addressed) or open an issue on GitHub. .PP Report tickets should contain a detailed description of the bug or enhancement request and at least an easily verifiable way of reproducing the issue or fix. Patches are always welcome, too \- and it's cheap to send pull-requests on GitHub. Please keep in mind that code changes are more likely accepted when they're bundled with an approving test. .PP If you think you've found a bug then please read \&\*(L"How to Report Bugs Effectively\*(R" by Simon Tatham: <http://www.chiark.greenend.org.uk/~sgtatham/bugs.html>. .SS "Where can I go for help with a concrete version?" .IX Subsection "Where can I go for help with a concrete version?" Bugs and feature requests are accepted against the latest version only. To get patches for earlier versions, you need to get an agreement with a developer of your choice \- who may or not report the issue and a suggested fix upstream (depends on the license you have chosen). .SS "Business support and maintenance" .IX Subsection "Business support and maintenance" Generally, in volunteered projects, there is no right for support. While every maintainer is happy to improve the provided software, spare time is limited. .PP For those who have a use case which requires guaranteed support, one of the maintainers should be hired or contracted. For business support you can contact Jens via his \s-1CPAN\s0 email address rehsackATcpan.org. Please keep in mind that business support is neither available for free nor are you eligible to receive any support based on the license distributed with this package. .SH "THANKS" .IX Header "THANKS" .SS "Tassilo von Parseval" .IX Subsection "Tassilo von Parseval" Credits go to a number of people: Steve Purkis for giving me namespace advice and James Keenan and Terrence Branno for their effort of keeping the \s-1CPAN\s0 tidier by making List::Utils obsolete. .PP Brian McCauley suggested the inclusion of \fIapply()\fR and provided the pure-Perl implementation for it. .PP Eric J. Roode asked me to add all functions from his module \f(CW\*(C`List::MoreUtil\*(C'\fR into this one. With minor modifications, the pure-Perl implementations of those are by him. .PP The bunch of people who almost immediately pointed out the many problems with the glitchy 0.07 release (Slaven Rezic, Ron Savage, \s-1CPAN\s0 testers). .PP A particularly nasty memory leak was spotted by Thomas A. Lowery. .PP Lars Thegler made me aware of problems with older Perl versions. .PP Anno Siegel de-orphaned \fIeach_arrayref()\fR. .PP David Filmer made me aware of a problem in each_arrayref that could ultimately lead to a segfault. .PP Ricardo Signes suggested the inclusion of \fIpart()\fR and provided the Perl-implementation. .PP Robin Huston kindly fixed a bug in perl's \s-1MULTICALL API\s0 to make the XS-implementation of \fIpart()\fR work. .SS "Jens Rehsack" .IX Subsection "Jens Rehsack" Credits goes to all people contributing feedback during the v0.400 development releases. .PP Special thanks goes to David Golden who spent a lot of effort to develop a design to support current state of \s-1CPAN\s0 as well as ancient software somewhere in the dark. He also contributed a lot of patches to refactor the \s-1API\s0 frontend to welcome any user of List::MoreUtils \- from ancient past to recently last used. .PP Toby Inkster provided a lot of useful feedback for sane importer code and was a nice sounding board for \s-1API\s0 discussions. .PP Peter Rabbitson provided a sane git repository setup containing entire package history. .SH "TODO" .IX Header "TODO" A pile of requests from other people is still pending further processing in my mailbox. This includes: .IP "\(bu" 4 List::Util export pass-through .Sp Allow \fBList::MoreUtils\fR to pass-through the regular List::Util functions to end users only need to \f(CW\*(C`use\*(C'\fR the one module. .IP "\(bu" 4 uniq_by(&@) .Sp Use code-reference to extract a key based on which the uniqueness is determined. Suggested by Aaron Crane. .IP "\(bu" 4 delete_index .IP "\(bu" 4 random_item .IP "\(bu" 4 random_item_delete_index .IP "\(bu" 4 list_diff_hash .IP "\(bu" 4 list_diff_inboth .IP "\(bu" 4 list_diff_infirst .IP "\(bu" 4 list_diff_insecond .Sp These were all suggested by Dan Muey. .IP "\(bu" 4 listify .Sp Always return a flat list when either a simple scalar value was passed or an array-reference. Suggested by Mark Summersault. .SH "SEE ALSO" .IX Header "SEE ALSO" List::Util, List::AllUtils, List::UtilsBy .SH "AUTHOR" .IX Header "AUTHOR" Jens Rehsack <rehsack \s-1AT\s0 cpan.org> .PP Adam Kennedy <adamk@cpan.org> .PP Tassilo von Parseval <tassilo.von.parseval@rwth\-aachen.de> .SH "COPYRIGHT AND LICENSE" .IX Header "COPYRIGHT AND LICENSE" Some parts copyright 2011 Aaron Crane. .PP Copyright 2004 \- 2010 by Tassilo von Parseval .PP Copyright 2013 \- 2016 by Jens Rehsack .PP This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.4 or, at your option, any later version of Perl 5 you may have available.