← Index
NYTProf Performance Profile   « line view »
For ../prof.pl
  Run on Thu Dec 15 15:23:56 2022
Reported on Thu Dec 15 15:27:02 2022

Filename/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/List/MoreUtils.pm
StatementsExecuted 125 statements in 4.17ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
1113.65ms3.96msList::MoreUtils::::BEGIN@24List::MoreUtils::BEGIN@24
1113.64ms3.83msList::MoreUtils::::BEGIN@21List::MoreUtils::BEGIN@21
1111.08ms6.15msList::MoreUtils::::BEGIN@11List::MoreUtils::BEGIN@11
11126µs26µsList::MoreUtils::::BEGIN@3List::MoreUtils::BEGIN@3
11110µs37µsList::MoreUtils::::BEGIN@66List::MoreUtils::BEGIN@66
1117µs10µsList::MoreUtils::::BEGIN@129List::MoreUtils::BEGIN@129
1117µs12µsList::MoreUtils::::BEGIN@54List::MoreUtils::BEGIN@54
1117µs9µsList::MoreUtils::::BEGIN@64List::MoreUtils::BEGIN@64
1115µs35µsList::MoreUtils::::BEGIN@5List::MoreUtils::BEGIN@5
1114µs6µsList::MoreUtils::::BEGIN@4List::MoreUtils::BEGIN@4
1113µs4µsList::MoreUtils::::BEGIN@134List::MoreUtils::BEGIN@134
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1package List::MoreUtils;
2
3232µs126µs
# spent 26µs within List::MoreUtils::BEGIN@3 which was called: # once (26µs+0s) by File::ShareDir::BEGIN@1 at line 3
use 5.008_001;
# spent 26µs making 1 call to List::MoreUtils::BEGIN@3
4216µs28µs
# spent 6µs (4+2) within List::MoreUtils::BEGIN@4 which was called: # once (4µs+2µs) by File::ShareDir::BEGIN@1 at line 4
use strict;
# spent 6µs making 1 call to List::MoreUtils::BEGIN@4 # spent 2µs making 1 call to strict::import
5260µs265µs
# spent 35µs (5+30) within List::MoreUtils::BEGIN@5 which was called: # once (5µs+30µs) by File::ShareDir::BEGIN@1 at line 5
use warnings;
# spent 35µs making 1 call to List::MoreUtils::BEGIN@5 # spent 30µs making 1 call to warnings::import
6
710smy $have_xs;
811µsour $VERSION = '0.430';
9
10BEGIN
11
# spent 6.15ms (1.08+5.07) within List::MoreUtils::BEGIN@11 which was called: # once (1.08ms+5.07ms) by File::ShareDir::BEGIN@1 at line 22
{
1214µs unless (defined($have_xs))
13 {
14 ## no critic (ErrorHandling::RequireCheckingReturnValueOfEval)
152824µs eval { require List::MoreUtils::XS; } unless $ENV{LIST_MOREUTILS_PP};
16 ## no critic (ErrorHandling::RequireCarping)
1710s die $@ if $@ && defined $ENV{LIST_MOREUTILS_PP} && $ENV{LIST_MOREUTILS_PP} == 0;
1812µs $have_xs = 0 + defined($INC{'List/MoreUtils/XS.pm'});
19 }
20
212537µs13.83ms
# spent 3.83ms (3.64+193µs) within List::MoreUtils::BEGIN@21 which was called: # once (3.64ms+193µs) by File::ShareDir::BEGIN@1 at line 21
use List::MoreUtils::PP qw();
# spent 3.83ms making 1 call to List::MoreUtils::BEGIN@21
22140µs16.15ms}
# spent 6.15ms making 1 call to List::MoreUtils::BEGIN@11
23
2421.39ms13.96ms
# spent 3.96ms (3.65+310µs) within List::MoreUtils::BEGIN@24 which was called: # once (3.65ms+310µs) by File::ShareDir::BEGIN@1 at line 24
use Exporter::Tiny qw();
# spent 3.96ms making 1 call to List::MoreUtils::BEGIN@24
25
2611µsmy @junctions = qw(any all none notall);
2712µsmy @v0_22 = qw(
28 true false
29 firstidx lastidx
30 insert_after insert_after_string
31 apply indexes
32 after after_incl before before_incl
33 firstval lastval
34 each_array each_arrayref
35 pairwise natatime
36 mesh uniq
37 minmax part
38 _XScompiled
39);
4010smy @v0_24 = qw(bsearch);
4110smy @v0_33 = qw(sort_by nsort_by);
4211µsmy @v0_400 = qw(one any_u all_u none_u notall_u one_u
43 firstres onlyidx onlyval onlyres lastres
44 singleton bsearchidx
45);
4611µsmy @v0_420 = qw(arrayify duplicates minmaxstr samples zip6 reduce_0 reduce_1 reduce_u
47 listcmp frequency occurrences mode
48 binsert bremove equal_range lower_bound upper_bound qsort
49 slide slideatatime);
50
5112µsmy @all_functions = (@junctions, @v0_22, @v0_24, @v0_33, @v0_400, @v0_420);
52
53## no critic (TestingAndDebugging::ProhibitNoStrict)
54281µs217µs
# spent 12µs (7+5) within List::MoreUtils::BEGIN@54 which was called: # once (7µs+5µs) by File::ShareDir::BEGIN@1 at line 54
no strict "refs";
# spent 12µs making 1 call to List::MoreUtils::BEGIN@54 # spent 5µs making 1 call to strict::unimport
5510sif ($have_xs)
56{
5710s my $x;
5812µs for (@all_functions)
59 {
6063244µs124110µs List::MoreUtils->can($_) or *$_ = $x if ($x = List::MoreUtils::XS->can($_));
# spent 110µs making 124 calls to UNIVERSAL::can, avg 887ns/call
61 }
62}
63179µs6523µsList::MoreUtils->can($_) or *$_ = List::MoreUtils::PP->can($_) for (@all_functions);
# spent 23µs making 65 calls to UNIVERSAL::can, avg 354ns/call
64236µs211µs
# spent 9µs (7+2) within List::MoreUtils::BEGIN@64 which was called: # once (7µs+2µs) by File::ShareDir::BEGIN@1 at line 64
use strict;
# spent 9µs making 1 call to List::MoreUtils::BEGIN@64 # spent 2µs making 1 call to strict::import
65## use critic (TestingAndDebugging::ProhibitNoStrict)
662134µs264µs
# spent 37µs (10+27) within List::MoreUtils::BEGIN@66 which was called: # once (10µs+27µs) by File::ShareDir::BEGIN@1 at line 66
use parent qw(Exporter::Tiny);
# spent 37µs making 1 call to List::MoreUtils::BEGIN@66 # spent 27µs making 1 call to parent::import
67
6817µsmy %alias_list = (
69 v0_22 => {
70 first_index => "firstidx",
71 last_index => "lastidx",
72 first_value => "firstval",
73 last_value => "lastval",
74 zip => "mesh",
75 },
76 v0_33 => {
77 distinct => "uniq",
78 },
79 v0_400 => {
80 first_result => "firstres",
81 only_index => "onlyidx",
82 only_value => "onlyval",
83 only_result => "onlyres",
84 last_result => "lastres",
85 bsearch_index => "bsearchidx",
86 },
87 v0_420 => {
88 bsearch_insert => "binsert",
89 bsearch_remove => "bremove",
90 zip_unflatten => "zip6",
91 },
92);
93
9417µsour @EXPORT_OK = (@all_functions, map { keys %$_ } values %alias_list);
95our %EXPORT_TAGS = (
96 all => \@EXPORT_OK,
97 'like_0.22' => [
98 any_u => {-as => 'any'},
99 all_u => {-as => 'all'},
100 none_u => {-as => 'none'},
101 notall_u => {-as => 'notall'},
102 @v0_22,
103 keys %{$alias_list{v0_22}},
104 ],
105 'like_0.24' => [
106 any_u => {-as => 'any'},
107 all_u => {-as => 'all'},
108 notall_u => {-as => 'notall'},
109 'none',
110 @v0_22,
111 @v0_24,
112 keys %{$alias_list{v0_22}},
113 ],
114 'like_0.33' => [
115 @junctions,
116 @v0_22,
117 # v0_24 functions were omitted
118 @v0_33,
119 keys %{$alias_list{v0_22}},
120110µs keys %{$alias_list{v0_33}},
121 ],
122);
123
12410sfor my $set (values %alias_list)
125{
12642µs for my $alias (keys %$set)
127 {
128 ## no critic (TestingAndDebugging::ProhibitNoStrict)
129227µs213µs
# spent 10µs (7+3) within List::MoreUtils::BEGIN@129 which was called: # once (7µs+3µs) by File::ShareDir::BEGIN@1 at line 129
no strict qw(refs);
# spent 10µs making 1 call to List::MoreUtils::BEGIN@129 # spent 3µs making 1 call to strict::unimport
1301531µs156µs *$alias = __PACKAGE__->can($set->{$alias});
# spent 6µs making 15 calls to UNIVERSAL::can, avg 400ns/call
131 ## use critic (TestingAndDebugging::ProhibitNoStrict)
132 }
133}
1342578µs25µs
# spent 4µs (3+1000ns) within List::MoreUtils::BEGIN@134 which was called: # once (3µs+1000ns) by File::ShareDir::BEGIN@1 at line 134
use strict;
# spent 4µs making 1 call to List::MoreUtils::BEGIN@134 # spent 1µs making 1 call to strict::import
135
136=pod
137
138=head1 NAME
139
140List::MoreUtils - Provide the stuff missing in List::Util
141
142=head1 SYNOPSIS
143
144 # import specific functions
145
146 use List::MoreUtils qw(any uniq);
147
148 if ( any { /foo/ } uniq @has_duplicates ) {
149 # do stuff
150 }
151
152 # import everything
153
154 use List::MoreUtils ':all';
155
156 # import by API
157
158 # has "original" any/all/none/notall behavior
159 use List::MoreUtils ':like_0.22';
160 # 0.22 + bsearch
161 use List::MoreUtils ':like_0.24';
162 # has "simplified" any/all/none/notall behavior + (n)sort_by
163 use List::MoreUtils ':like_0.33';
164
165=head1 DESCRIPTION
166
167B<List::MoreUtils> provides some trivial but commonly needed functionality on
168lists which is not going to go into L<List::Util>.
169
170All of the below functions are implementable in only a couple of lines of Perl
171code. Using the functions from this module however should give slightly better
172performance as everything is implemented in C. The pure-Perl implementation of
173these functions only serves as a fallback in case the C portions of this module
174couldn't be compiled on this machine.
175
176=head1 EXPORTS
177
178=head2 Default behavior
179
180Nothing by default. To import all of this module's symbols use the C<:all> tag.
181Otherwise functions can be imported by name as usual:
182
183 use List::MoreUtils ':all';
184
185 use List::MoreUtils qw{ any firstidx };
186
187Because historical changes to the API might make upgrading List::MoreUtils
188difficult for some projects, the legacy API is available via special import
189tags.
190
191=head2 Like version 0.22 (last release with original API)
192
193This API was available from 2006 to 2009, returning undef for empty lists on
194C<all>/C<any>/C<none>/C<notall>:
195
196 use List::MoreUtils ':like_0.22';
197
198This import tag will import all functions available as of version 0.22.
199However, it will import C<any_u> as C<any>, C<all_u> as C<all>, C<none_u> as
200C<none>, and C<notall_u> as C<notall>.
201
202=head2 Like version 0.24 (first incompatible change)
203
204This API was available from 2010 to 2011. It changed the return value of C<none>
205and added the C<bsearch> function.
206
207 use List::MoreUtils ':like_0.24';
208
209This import tag will import all functions available as of version 0.24.
210However it will import C<any_u> as C<any>, C<all_u> as C<all>, and
211C<notall_u> as C<notall>. It will import C<none> as described in
212the documentation below (true for empty list).
213
214=head2 Like version 0.33 (second incompatible change)
215
216This API was available from 2011 to 2014. It is widely used in several CPAN
217modules and thus it's closest to the current API. It changed the return values
218of C<any>, C<all>, and C<notall>. It added the C<sort_by> and C<nsort_by> functions
219and the C<distinct> alias for C<uniq>. It omitted C<bsearch>.
220
221 use List::MoreUtils ':like_0.33';
222
223This import tag will import all functions available as of version 0.33. Note:
224it will not import C<bsearch> for consistency with the 0.33 API.
225
226=head1 FUNCTIONS
227
228=head2 Junctions
229
230=head3 I<Treatment of an empty list>
231
232There are two schools of thought for how to evaluate a junction on an
233empty list:
234
235=over
236
237=item *
238
239Reduction to an identity (boolean)
240
241=item *
242
243Result is undefined (three-valued)
244
245=back
246
247In the first case, the result of the junction applied to the empty list is
248determined by a mathematical reduction to an identity depending on whether
249the underlying comparison is "or" or "and". Conceptually:
250
251 "any are true" "all are true"
252 -------------- --------------
253 2 elements: A || B || 0 A && B && 1
254 1 element: A || 0 A && 1
255 0 elements: 0 1
256
257In the second case, three-value logic is desired, in which a junction
258applied to an empty list returns C<undef> rather than true or false
259
260Junctions with a C<_u> suffix implement three-valued logic. Those
261without are boolean.
262
263=head3 all BLOCK LIST
264
265=head3 all_u BLOCK LIST
266
267Returns a true value if all items in LIST meet the criterion given through
268BLOCK. Sets C<$_> for each item in LIST in turn:
269
270 print "All values are non-negative"
271 if all { $_ >= 0 } ($x, $y, $z);
272
273For an empty LIST, C<all> returns true (i.e. no values failed the condition)
274and C<all_u> returns C<undef>.
275
276Thus, C<< all_u(@list) >> is equivalent to C<< @list ? all(@list) : undef >>.
277
278B<Note>: because Perl treats C<undef> as false, you must check the return value
279of C<all_u> with C<defined> or you will get the opposite result of what you
280expect.
281
282=head3 any BLOCK LIST
283
284=head3 any_u BLOCK LIST
285
286Returns a true value if any item in LIST meets the criterion given through
287BLOCK. Sets C<$_> for each item in LIST in turn:
288
289 print "At least one non-negative value"
290 if any { $_ >= 0 } ($x, $y, $z);
291
292For an empty LIST, C<any> returns false and C<any_u> returns C<undef>.
293
294Thus, C<< any_u(@list) >> is equivalent to C<< @list ? any(@list) : undef >>.
295
296=head3 none BLOCK LIST
297
298=head3 none_u BLOCK LIST
299
300Logically the negation of C<any>. Returns a true value if no item in LIST meets
301the criterion given through BLOCK. Sets C<$_> for each item in LIST in turn:
302
303 print "No non-negative values"
304 if none { $_ >= 0 } ($x, $y, $z);
305
306For an empty LIST, C<none> returns true (i.e. no values failed the condition)
307and C<none_u> returns C<undef>.
308
309Thus, C<< none_u(@list) >> is equivalent to C<< @list ? none(@list) : undef >>.
310
311B<Note>: because Perl treats C<undef> as false, you must check the return value
312of C<none_u> with C<defined> or you will get the opposite result of what you
313expect.
314
315=head3 notall BLOCK LIST
316
317=head3 notall_u BLOCK LIST
318
319Logically the negation of C<all>. Returns a true value if not all items in LIST
320meet the criterion given through BLOCK. Sets C<$_> for each item in LIST in
321turn:
322
323 print "Not all values are non-negative"
324 if notall { $_ >= 0 } ($x, $y, $z);
325
326For an empty LIST, C<notall> returns false and C<notall_u> returns C<undef>.
327
328Thus, C<< notall_u(@list) >> is equivalent to C<< @list ? notall(@list) : undef >>.
329
330=head3 one BLOCK LIST
331
332=head3 one_u BLOCK LIST
333
334Returns a true value if precisely one item in LIST meets the criterion
335given through BLOCK. Sets C<$_> for each item in LIST in turn:
336
337 print "Precisely one value defined"
338 if one { defined($_) } @list;
339
340Returns false otherwise.
341
342For an empty LIST, C<one> returns false and C<one_u> returns C<undef>.
343
344The expression C<one BLOCK LIST> is almost equivalent to
345C<1 == true BLOCK LIST>, except for short-cutting.
346Evaluation of BLOCK will immediately stop at the second true value.
347
348=head2 Transformation
349
350=head3 apply BLOCK LIST
351
352Applies BLOCK to each item in LIST and returns a list of the values after BLOCK
353has been applied. In scalar context, the last element is returned. This
354function is similar to C<map> but will not modify the elements of the input
355list:
356
357 my @list = (1 .. 4);
358 my @mult = apply { $_ *= 2 } @list;
359 print "\@list = @list\n";
360 print "\@mult = @mult\n";
361 __END__
362 @list = 1 2 3 4
363 @mult = 2 4 6 8
364
365Think of it as syntactic sugar for
366
367 for (my @mult = @list) { $_ *= 2 }
368
369=head3 insert_after BLOCK VALUE LIST
370
371Inserts VALUE after the first item in LIST for which the criterion in BLOCK is
372true. Sets C<$_> for each item in LIST in turn.
373
374 my @list = qw/This is a list/;
375 insert_after { $_ eq "a" } "longer" => @list;
376 print "@list";
377 __END__
378 This is a longer list
379
380=head3 insert_after_string STRING VALUE LIST
381
382Inserts VALUE after the first item in LIST which is equal to STRING.
383
384 my @list = qw/This is a list/;
385 insert_after_string "a", "longer" => @list;
386 print "@list";
387 __END__
388 This is a longer list
389
390=head3 pairwise BLOCK ARRAY1 ARRAY2
391
392Evaluates BLOCK for each pair of elements in ARRAY1 and ARRAY2 and returns a
393new list consisting of BLOCK's return values. The two elements are set to C<$a>
394and C<$b>. Note that those two are aliases to the original value so changing
395them will modify the input arrays.
396
397 @a = (1 .. 5);
398 @b = (11 .. 15);
399 @x = pairwise { $a + $b } @a, @b; # returns 12, 14, 16, 18, 20
400
401 # mesh with pairwise
402 @a = qw/a b c/;
403 @b = qw/1 2 3/;
404 @x = pairwise { ($a, $b) } @a, @b; # returns a, 1, b, 2, c, 3
405
406=head3 mesh ARRAY1 ARRAY2 [ ARRAY3 ... ]
407
408=head3 zip ARRAY1 ARRAY2 [ ARRAY3 ... ]
409
410Returns a list consisting of the first elements of each array, then
411the second, then the third, etc, until all arrays are exhausted.
412
413Examples:
414
415 @x = qw/a b c d/;
416 @y = qw/1 2 3 4/;
417 @z = mesh @x, @y; # returns a, 1, b, 2, c, 3, d, 4
418
419 @a = ('x');
420 @b = ('1', '2');
421 @c = qw/zip zap zot/;
422 @d = mesh @a, @b, @c; # x, 1, zip, undef, 2, zap, undef, undef, zot
423
424C<zip> is an alias for C<mesh>.
425
426=head3 zip6
427
428=head3 zip_unflatten
429
430Returns a list of arrays consisting of the first elements of each array,
431then the second, then the third, etc, until all arrays are exhausted.
432
433 @x = qw/a b c d/;
434 @y = qw/1 2 3 4/;
435 @z = zip6 @x, @y; # returns [a, 1], [b, 2], [c, 3], [d, 4]
436
437 @a = ('x');
438 @b = ('1', '2');
439 @c = qw/zip zap zot/;
440 @d = zip6 @a, @b, @c; # [x, 1, zip], [undef, 2, zap], [undef, undef, zot]
441
442C<zip_unflatten> is an alias for C<zip6>.
443
444=head3 listcmp ARRAY0 ARRAY1 [ ARRAY2 ... ]
445
446Returns an associative list of elements and every I<id> of the list it
447was found in. Allows easy implementation of @a & @b, @a | @b, @a ^ @b and
448so on.
449Undefined entries in any given array are skipped.
450
451 my @a = qw(one two three four five six seven eight nine ten eleven twelve thirteen);
452 my @b = qw(two three five seven eleven thirteen seventeen);
453 my @c = qw(one one two three five eight thirteen twentyone);
454 my %cmp = listcmp @a, @b, @c; # returns (one => [0, 2], two => [0, 1, 2], three => [0, 1, 2], four => [0], ...)
455
456 my @seq = (1, 2, 3);
457 my @prim = (undef, 2, 3, 5);
458 my @fib = (1, 1, 2);
459 my %cmp = listcmp @seq, @prim, @fib;
460 # returns ( 1 => [0, 2], 2 => [0, 1, 2], 3 => [0, 1], 5 => [1] )
461
462=head3 arrayify LIST[,LIST[,LIST...]]
463
464Returns a list consisting of each element of given arrays. Recursive arrays
465are flattened, too.
466
467 @a = (1, [[2], 3], 4, [5], 6, [7], 8, 9);
468 @l = arrayify @a; # returns 1, 2, 3, 4, 5, 6, 7, 8, 9
469
470=head3 uniq LIST
471
472=head3 distinct LIST
473
474Returns a new list by stripping duplicate values in LIST by comparing
475the values as hash keys, except that undef is considered separate from ''.
476The order of elements in the returned list is the same as in LIST. In
477scalar context, returns the number of unique elements in LIST.
478
479 my @x = uniq 1, 1, 2, 2, 3, 5, 3, 4; # returns 1 2 3 5 4
480 my $x = uniq 1, 1, 2, 2, 3, 5, 3, 4; # returns 5
481 # returns "Mike", "Michael", "Richard", "Rick"
482 my @n = distinct "Mike", "Michael", "Richard", "Rick", "Michael", "Rick"
483 # returns "A8", "", undef, "A5", "S1"
484 my @s = distinct "A8", "", undef, "A5", "S1", "A5", "A8"
485 # returns "Giulia", "Giulietta", undef, "", 156, "GTA", "GTV", 159, "Brera", "4C"
486 my @w = uniq "Giulia", "Giulietta", undef, "", 156, "GTA", "GTV", 159, "Brera", "4C", "Giulietta", "Giulia"
487
488C<distinct> is an alias for C<uniq>.
489
490B<RT#49800> can be used to give feedback about this behavior.
491
492=head3 singleton LIST
493
494Returns a new list by stripping values in LIST occurring more than once by
495comparing the values as hash keys, except that undef is considered separate
496from ''. The order of elements in the returned list is the same as in LIST.
497In scalar context, returns the number of elements occurring only once in LIST.
498
499 my @x = singleton 1,1,2,2,3,4,5 # returns 3 4 5
500
501=head3 duplicates LIST
502
503Returns a new list by stripping values in LIST occurring less than twice by
504comparing the values as hash keys, except that undef is considered separate
505from ''. The order of elements in the returned list is the same as in LIST.
506In scalar context, returns the number of elements occurring more than once
507in LIST.
508
509 my @y = duplicates 1,1,2,4,7,2,3,4,6,9; #returns 1,2,4
510
511=head3 frequency LIST
512
513Returns an associative list of distinct values and the corresponding frequency.
514
515 my @f = frequency values %radio_nrw; # returns (
516 # 'Deutschlandfunk (DLF)' => 9, 'WDR 3' => 10,
517 # 'WDR 4' => 11, 'WDR 5' => 14, 'WDR Eins Live' => 14,
518 # 'Deutschlandradio Kultur' => 8,...)
519
520=head3 occurrences LIST
521
522Returns a new list of frequencies and the corresponding values from LIST.
523
524 my @o = occurrences ((1) x 3, (2) x 4, (3) x 2, (4) x 7, (5) x 2, (6) x 4);
525 # @o = (undef, undef, [3, 5], [1], [2, 6], undef, undef, [4]);
526
527=head3 mode LIST
528
529Returns the modal value of LIST. In scalar context, just the modal value
530is returned, in list context all probes occurring I<modal> times are returned,
531too.
532
533 my @m = mode ((1) x 3, (2) x 4, (3) x 2, (4) x 7, (5) x 2, (6) x 4, (7) x 3, (8) x 7);
534 # @m = (7, 4, 8) - bimodal LIST
535
536=head3 slide BLOCK LIST
537
538The function C<slide> operates on pairs of list elements like:
539
540 my @s = slide { "$a and $b" } (0..3);
541 # @s = ("0 and 1", "1 and 2", "2 and 3")
542
543The idea behind this function is a kind of magnifying glass that is moved
544along a list and calls C<BLOCK> every time the next list item is reached.
545
546=head2 Partitioning
547
548=head3 after BLOCK LIST
549
550Returns a list of the values of LIST after (and not including) the point
551where BLOCK returns a true value. Sets C<$_> for each element in LIST in turn.
552
553 @x = after { $_ % 5 == 0 } (1..9); # returns 6, 7, 8, 9
554
555=head3 after_incl BLOCK LIST
556
557Same as C<after> but also includes the element for which BLOCK is true.
558
559=head3 before BLOCK LIST
560
561Returns a list of values of LIST up to (and not including) the point where BLOCK
562returns a true value. Sets C<$_> for each element in LIST in turn.
563
564=head3 before_incl BLOCK LIST
565
566Same as C<before> but also includes the element for which BLOCK is true.
567
568=head3 part BLOCK LIST
569
570Partitions LIST based on the return value of BLOCK which denotes into which
571partition the current value is put.
572
573Returns a list of the partitions thusly created. Each partition created is a
574reference to an array.
575
576 my $i = 0;
577 my @part = part { $i++ % 2 } 1 .. 8; # returns [1, 3, 5, 7], [2, 4, 6, 8]
578
579You can have a sparse list of partitions as well where non-set partitions will
580be undef:
581
582 my @part = part { 2 } 1 .. 10; # returns undef, undef, [ 1 .. 10 ]
583
584Be careful with negative values, though:
585
586 my @part = part { -1 } 1 .. 10;
587 __END__
588 Modification of non-creatable array value attempted, subscript -1 ...
589
590Negative values are only ok when they refer to a partition previously created:
591
592 my @idx = ( 0, 1, -1 );
593 my $i = 0;
594 my @part = part { $idx[$i++ % 3] } 1 .. 8; # [1, 4, 7], [2, 3, 5, 6, 8]
595
596=head3 samples COUNT LIST
597
598Returns a new list containing COUNT random samples from LIST. Is similar to
599L<List::Util/shuffle>, but stops after COUNT.
600
601 @r = samples 10, 1..10; # same as shuffle
602 @r2 = samples 5, 1..10; # gives 5 values from 1..10;
603
604=head2 Iteration
605
606=head3 each_array ARRAY1 ARRAY2 ...
607
608Creates an array iterator to return the elements of the list of arrays ARRAY1,
609ARRAY2 throughout ARRAYn in turn. That is, the first time it is called, it
610returns the first element of each array. The next time, it returns the second
611elements. And so on, until all elements are exhausted.
612
613This is useful for looping over more than one array at once:
614
615 my $ea = each_array(@a, @b, @c);
616 while ( my ($a, $b, $c) = $ea->() ) { .... }
617
618The iterator returns the empty list when it reached the end of all arrays.
619
620If the iterator is passed an argument of 'C<index>', then it returns
621the index of the last fetched set of values, as a scalar.
622
623=head3 each_arrayref LIST
624
625Like each_array, but the arguments are references to arrays, not the
626plain arrays.
627
628=head3 natatime EXPR, LIST
629
630Creates an array iterator, for looping over an array in chunks of
631C<$n> items at a time. (n at a time, get it?). An example is
632probably a better explanation than I could give in words.
633
634Example:
635
636 my @x = ('a' .. 'g');
637 my $it = natatime 3, @x;
638 while (my @vals = $it->())
639 {
640 print "@vals\n";
641 }
642
643This prints
644
645 a b c
646 d e f
647 g
648
649=head3 slideatatime STEP, WINDOW, LIST
650
651Creates an array iterator, for looping over an array in chunks of
652C<$windows-size> items at a time.
653
654The idea behind this function is a kind of magnifying glass (finer
655controllable compared to L</slide>) that is moved along a list.
656
657Example:
658
659 my @x = ('a' .. 'g');
660 my $it = slideatatime 2, 3, @x;
661 while (my @vals = $it->())
662 {
663 print "@vals\n";
664 }
665
666This prints
667
668 a b c
669 c d e
670 e f g
671 g
672
673=head2 Searching
674
675=head3 firstval BLOCK LIST
676
677=head3 first_value BLOCK LIST
678
679Returns the first element in LIST for which BLOCK evaluates to true. Each
680element of LIST is set to C<$_> in turn. Returns C<undef> if no such element
681has been found.
682
683C<first_value> is an alias for C<firstval>.
684
685=head3 onlyval BLOCK LIST
686
687=head3 only_value BLOCK LIST
688
689Returns the only element in LIST for which BLOCK evaluates to true. Sets
690C<$_> for each item in LIST in turn. Returns C<undef> if no such element
691has been found.
692
693C<only_value> is an alias for C<onlyval>.
694
695=head3 lastval BLOCK LIST
696
697=head3 last_value BLOCK LIST
698
699Returns the last value in LIST for which BLOCK evaluates to true. Each element
700of LIST is set to C<$_> in turn. Returns C<undef> if no such element has been
701found.
702
703C<last_value> is an alias for C<lastval>.
704
705=head3 firstres BLOCK LIST
706
707=head3 first_result BLOCK LIST
708
709Returns the result of BLOCK for the first element in LIST for which BLOCK
710evaluates to true. Each element of LIST is set to C<$_> in turn. Returns
711C<undef> if no such element has been found.
712
713C<first_result> is an alias for C<firstres>.
714
715=head3 onlyres BLOCK LIST
716
717=head3 only_result BLOCK LIST
718
719Returns the result of BLOCK for the first element in LIST for which BLOCK
720evaluates to true. Sets C<$_> for each item in LIST in turn. Returns
721C<undef> if no such element has been found.
722
723C<only_result> is an alias for C<onlyres>.
724
725=head3 lastres BLOCK LIST
726
727=head3 last_result BLOCK LIST
728
729Returns the result of BLOCK for the last element in LIST for which BLOCK
730evaluates to true. Each element of LIST is set to C<$_> in turn. Returns
731C<undef> if no such element has been found.
732
733C<last_result> is an alias for C<lastres>.
734
735=head3 indexes BLOCK LIST
736
737Evaluates BLOCK for each element in LIST (assigned to C<$_>) and returns a list
738of the indices of those elements for which BLOCK returned a true value. This is
739just like C<grep> only that it returns indices instead of values:
740
741 @x = indexes { $_ % 2 == 0 } (1..10); # returns 1, 3, 5, 7, 9
742
743=head3 firstidx BLOCK LIST
744
745=head3 first_index BLOCK LIST
746
747Returns the index of the first element in LIST for which the criterion in BLOCK
748is true. Sets C<$_> for each item in LIST in turn:
749
750 my @list = (1, 4, 3, 2, 4, 6);
751 printf "item with index %i in list is 4", firstidx { $_ == 4 } @list;
752 __END__
753 item with index 1 in list is 4
754
755Returns C<-1> if no such item could be found.
756
757C<first_index> is an alias for C<firstidx>.
758
759=head3 onlyidx BLOCK LIST
760
761=head3 only_index BLOCK LIST
762
763Returns the index of the only element in LIST for which the criterion
764in BLOCK is true. Sets C<$_> for each item in LIST in turn:
765
766 my @list = (1, 3, 4, 3, 2, 4);
767 printf "uniqe index of item 2 in list is %i", onlyidx { $_ == 2 } @list;
768 __END__
769 unique index of item 2 in list is 4
770
771Returns C<-1> if either no such item or more than one of these
772has been found.
773
774C<only_index> is an alias for C<onlyidx>.
775
776=head3 lastidx BLOCK LIST
777
778=head3 last_index BLOCK LIST
779
780Returns the index of the last element in LIST for which the criterion in BLOCK
781is true. Sets C<$_> for each item in LIST in turn:
782
783 my @list = (1, 4, 3, 2, 4, 6);
784 printf "item with index %i in list is 4", lastidx { $_ == 4 } @list;
785 __END__
786 item with index 4 in list is 4
787
788Returns C<-1> if no such item could be found.
789
790C<last_index> is an alias for C<lastidx>.
791
792=head2 Sorting
793
794=head3 sort_by BLOCK LIST
795
796Returns the list of values sorted according to the string values returned by the
797KEYFUNC block or function. A typical use of this may be to sort objects according
798to the string value of some accessor, such as
799
800 sort_by { $_->name } @people
801
802The key function is called in scalar context, being passed each value in turn as
803both $_ and the only argument in the parameters, @_. The values are then sorted
804according to string comparisons on the values returned.
805This is equivalent to
806
807 sort { $a->name cmp $b->name } @people
808
809except that it guarantees the name accessor will be executed only once per value.
810One interesting use-case is to sort strings which may have numbers embedded in them
811"naturally", rather than lexically.
812
813 sort_by { s/(\d+)/sprintf "%09d", $1/eg; $_ } @strings
814
815This sorts strings by generating sort keys which zero-pad the embedded numbers to
816some level (9 digits in this case), helping to ensure the lexical sort puts them
817in the correct order.
818
819=head3 nsort_by BLOCK LIST
820
821Similar to sort_by but compares its key values numerically.
822
823=head3 qsort BLOCK ARRAY
824
825This sorts the given array B<in place> using the given compare code. Except for
826tiny compare code like C<< $a <=> $b >>, qsort is much faster than Perl's C<sort>
827depending on the version.
828
829Compared 5.8 and 5.26:
830
831 my @rl;
832 for(my $i = 0; $i < 1E6; ++$i) { push @rl, rand(1E5) }
833 my $idx;
834
835 sub ext_cmp { $_[0] <=> $_[1] }
836
837 cmpthese( -60, {
838 'qsort' => sub {
839 my @qrl = @rl;
840 qsort { ext_cmp($a, $b) } @qrl;
841 $idx = bsearchidx { ext_cmp($_, $rl[0]) } @qrl
842 },
843 'reverse qsort' => sub {
844 my @qrl = @rl;
845 qsort { ext_cmp($b, $a) } @qrl;
846 $idx = bsearchidx { ext_cmp($rl[0], $_) } @qrl
847 },
848 'sort' => sub {
849 my @srl = @rl;
850 @srl = sort { ext_cmp($a, $b) } @srl;
851 $idx = bsearchidx { ext_cmp($_, $rl[0]) } @srl
852 },
853 'reverse sort' => sub {
854 my @srl = @rl;
855 @srl = sort { ext_cmp($b, $a) } @srl;
856 $idx = bsearchidx { ext_cmp($rl[0], $_) } @srl
857 },
858 });
859
8605.8 results
861
862 s/iter reverse sort sort reverse qsort qsort
863 reverse sort 6.21 -- -0% -8% -10%
864 sort 6.19 0% -- -7% -10%
865 reverse qsort 5.73 8% 8% -- -2%
866 qsort 5.60 11% 11% 2% --
867
8685.26 results
869
870 s/iter reverse sort sort reverse qsort qsort
871 reverse sort 4.54 -- -0% -96% -96%
872 sort 4.52 0% -- -96% -96%
873 reverse qsort 0.203 2139% 2131% -- -19%
874 qsort 0.164 2666% 2656% 24% --
875
876Use it where external data sources might have to be compared (think of L<Unix::Statgrab>
877"tables").
878
879C<qsort> is available from List::MoreUtils::XS only. It's insane to maintain
880a wrapper around Perl's sort nor having a pure Perl implementation. One could
881create a flip-book in same speed as PP runs a qsort.
882
883=head2 Searching in sorted Lists
884
885=head3 bsearch BLOCK LIST
886
887Performs a binary search on LIST which must be a sorted list of values. BLOCK
888must return a negative value if the current element (stored in C<$_>) is smaller,
889a positive value if it is bigger and zero if it matches.
890
891Returns a boolean value in scalar context. In list context, it returns the element
892if it was found, otherwise the empty list.
893
894=head3 bsearchidx BLOCK LIST
895
896=head3 bsearch_index BLOCK LIST
897
898Performs a binary search on LIST which must be a sorted list of values. BLOCK
899must return a negative value if the current element (stored in C<$_>) is smaller,
900a positive value if it is bigger and zero if it matches.
901
902Returns the index of found element, otherwise C<-1>.
903
904C<bsearch_index> is an alias for C<bsearchidx>.
905
906=head3 lower_bound BLOCK LIST
907
908Returns the index of the first element in LIST which does not compare
909I<less than val>. Technically it's the first element in LIST which does
910not return a value below zero when passed to BLOCK.
911
912 @ids = (1, 1, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 6, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 11, 13, 13, 13, 17);
913 $lb = lower_bound { $_ <=> 2 } @ids; # returns 2
914 $lb = lower_bound { $_ <=> 4 } @ids; # returns 10
915
916lower_bound has a complexity of O(log n).
917
918=head3 upper_bound BLOCK LIST
919
920Returns the index of the first element in LIST which does not compare
921I<greater than val>. Technically it's the first element in LIST which does
922not return a value below or equal to zero when passed to BLOCK.
923
924 @ids = (1, 1, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 6, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 11, 13, 13, 13, 17);
925 $lb = upper_bound { $_ <=> 2 } @ids; # returns 4
926 $lb = upper_bound { $_ <=> 4 } @ids; # returns 14
927
928upper_bound has a complexity of O(log n).
929
930=head3 equal_range BLOCK LIST
931
932Returns a pair of indices containing the lower_bound and the upper_bound.
933
934=head2 Operations on sorted Lists
935
936=head3 binsert BLOCK ITEM LIST
937
938=head3 bsearch_insert BLOCK ITEM LIST
939
940Performs a binary search on LIST which must be a sorted list of values. BLOCK
941must return a negative value if the current element (stored in C<$_>) is smaller,
942a positive value if it is bigger and zero if it matches.
943
944ITEM is inserted at the index where the ITEM should be placed (based on above
945search). That means, it's inserted before the next bigger element.
946
947 @l = (2,3,5,7);
948 binsert { $_ <=> 4 } 4, @l; # @l = (2,3,4,5,7)
949 binsert { $_ <=> 6 } 42, @l; # @l = (2,3,4,42,7)
950
951You take care that the inserted element matches the compare result.
952
953=head3 bremove BLOCK LIST
954
955=head3 bsearch_remove BLOCK LIST
956
957Performs a binary search on LIST which must be a sorted list of values. BLOCK
958must return a negative value if the current element (stored in C<$_>) is smaller,
959a positive value if it is bigger and zero if it matches.
960
961The item at the found position is removed and returned.
962
963 @l = (2,3,4,5,7);
964 bremove { $_ <=> 4 }, @l; # @l = (2,3,5,7);
965
966=head2 Counting and calculation
967
968=head3 true BLOCK LIST
969
970Counts the number of elements in LIST for which the criterion in BLOCK is true.
971Sets C<$_> for each item in LIST in turn:
972
973 printf "%i item(s) are defined", true { defined($_) } @list;
974
975=head3 false BLOCK LIST
976
977Counts the number of elements in LIST for which the criterion in BLOCK is false.
978Sets C<$_> for each item in LIST in turn:
979
980 printf "%i item(s) are not defined", false { defined($_) } @list;
981
982=head3 reduce_0 BLOCK LIST
983
984Reduce LIST by calling BLOCK in scalar context for each element of LIST.
985C<$a> contains the progressional result and is initialized with 0.
986C<$b> contains the current processed element of LIST and C<$_> contains the
987index of the element in C<$b>.
988
989The idea behind reduce_0 is B<summation> (addition of a sequence of numbers).
990
991=head3 reduce_1 BLOCK LIST
992
993Reduce LIST by calling BLOCK in scalar context for each element of LIST.
994C<$a> contains the progressional result and is initialized with 1.
995C<$b> contains the current processed element of LIST and C<$_> contains the
996index of the element in C<$b>.
997
998The idea behind reduce_1 is product of a sequence of numbers.
999
1000=head3 reduce_u BLOCK LIST
1001
1002Reduce LIST by calling BLOCK in scalar context for each element of LIST.
1003C<$a> contains the progressional result and is uninitialized.
1004C<$b> contains the current processed element of LIST and C<$_> contains the
1005index of the element in C<$b>.
1006
1007This function has been added if one might need the extra of the index
1008value but need an individual initialization.
1009
1010B<Use with caution>: In most cases L<List::Util/reduce> will do the
1011job better.
1012
1013=head3 minmax LIST
1014
1015Calculates the minimum and maximum of LIST and returns a two element list with
1016the first element being the minimum and the second the maximum. Returns the
1017empty list if LIST was empty.
1018
1019The C<minmax> algorithm differs from a naive iteration over the list where each
1020element is compared to two values being the so far calculated min and max value
1021in that it only requires 3n/2 - 2 comparisons. Thus it is the most efficient
1022possible algorithm.
1023
1024However, the Perl implementation of it has some overhead simply due to the fact
1025that there are more lines of Perl code involved. Therefore, LIST needs to be
1026fairly big in order for C<minmax> to win over a naive implementation. This
1027limitation does not apply to the XS version.
1028
1029=head3 minmaxstr LIST
1030
1031Computes the minimum and maximum of LIST using string compare and returns a
1032two element list with the first element being the minimum and the second the
1033maximum. Returns the empty list if LIST was empty.
1034
1035The implementation is similar to C<minmax>.
1036
1037=head1 ENVIRONMENT
1038
1039When C<LIST_MOREUTILS_PP> is set, the module will always use the pure-Perl
1040implementation and not the XS one. This environment variable is really just
1041there for the test-suite to force testing the Perl implementation, and possibly
1042for reporting of bugs. I don't see any reason to use it in a production
1043environment.
1044
1045=head1 MAINTENANCE
1046
1047The maintenance goal is to preserve the documented semantics of the API;
1048bug fixes that bring actual behavior in line with semantics are allowed.
1049New API functions may be added over time. If a backwards incompatible
1050change is unavoidable, we will attempt to provide support for the legacy
1051API using the same export tag mechanism currently in place.
1052
1053This module attempts to use few non-core dependencies. Non-core
1054configuration and testing modules will be bundled when reasonable;
1055run-time dependencies will be added only if they deliver substantial
1056benefit.
1057
1058=head1 CONTRIBUTING
1059
1060While contributions are appreciated, a contribution should not cause more
1061effort for the maintainer than the contribution itself saves (see
1062L<Open Source Contribution Etiquette|http://tirania.org/blog/archive/2010/Dec-31.html>).
1063
1064To get more familiar where help could be needed - see L<List::MoreUtils::Contributing>.
1065
1066=head1 BUGS
1067
1068There is a problem with a bug in 5.6.x perls. It is a syntax error to write
1069things like:
1070
1071 my @x = apply { s/foo/bar/ } qw{ foo bar baz };
1072
1073It has to be written as either
1074
1075 my @x = apply { s/foo/bar/ } 'foo', 'bar', 'baz';
1076
1077or
1078
1079 my @x = apply { s/foo/bar/ } my @dummy = qw/foo bar baz/;
1080
1081Perl 5.5.x and Perl 5.8.x don't suffer from this limitation.
1082
1083If you have a functionality that you could imagine being in this module, please
1084drop me a line. This module's policy will be less strict than L<List::Util>'s
1085when it comes to additions as it isn't a core module.
1086
1087When you report bugs, it would be nice if you could additionally give me the
1088output of your program with the environment variable C<LIST_MOREUTILS_PP> set
1089to a true value. That way I know where to look for the problem (in XS,
1090pure-Perl or possibly both).
1091
1092=head1 SUPPORT
1093
1094Bugs should always be submitted via the CPAN bug tracker.
1095
1096You can find documentation for this module with the perldoc command.
1097
1098 perldoc List::MoreUtils
1099
1100You can also look for information at:
1101
1102=over 4
1103
1104=item * RT: CPAN's request tracker
1105
1106L<https://rt.cpan.org/Dist/Display.html?Name=List-MoreUtils>
1107
1108=item * AnnoCPAN: Annotated CPAN documentation
1109
1110L<http://annocpan.org/dist/List-MoreUtils>
1111
1112=item * CPAN Ratings
1113
1114L<http://cpanratings.perl.org/dist/List-MoreUtils>
1115
1116=item * MetaCPAN
1117
1118L<https://metacpan.org/release/List-MoreUtils>
1119
1120=item * CPAN Search
1121
1122L<http://search.cpan.org/dist/List-MoreUtils/>
1123
1124=item * Git Repository
1125
1126L<https://github.com/perl5-utils/List-MoreUtils>
1127
1128=back
1129
1130=head2 Where can I go for help?
1131
1132If you have a bug report, a patch or a suggestion, please open a new
1133report ticket at CPAN (but please check previous reports first in case
1134your issue has already been addressed) or open an issue on GitHub.
1135
1136Report tickets should contain a detailed description of the bug or
1137enhancement request and at least an easily verifiable way of
1138reproducing the issue or fix. Patches are always welcome, too - and
1139it's cheap to send pull-requests on GitHub. Please keep in mind that
1140code changes are more likely accepted when they're bundled with an
1141approving test.
1142
1143If you think you've found a bug then please read
1144"How to Report Bugs Effectively" by Simon Tatham:
1145L<http://www.chiark.greenend.org.uk/~sgtatham/bugs.html>.
1146
1147=head2 Where can I go for help with a concrete version?
1148
1149Bugs and feature requests are accepted against the latest version
1150only. To get patches for earlier versions, you need to get an
1151agreement with a developer of your choice - who may or not report the
1152issue and a suggested fix upstream (depends on the license you have
1153chosen).
1154
1155=head2 Business support and maintenance
1156
1157Generally, in volunteered projects, there is no right for support.
1158While every maintainer is happy to improve the provided software,
1159spare time is limited.
1160
1161For those who have a use case which requires guaranteed support, one of
1162the maintainers should be hired or contracted. For business support you
1163can contact Jens via his CPAN email address rehsackATcpan.org. Please
1164keep in mind that business support is neither available for free nor
1165are you eligible to receive any support based on the license distributed
1166with this package.
1167
1168=head1 THANKS
1169
1170=head2 Tassilo von Parseval
1171
1172Credits go to a number of people: Steve Purkis for giving me namespace advice
1173and James Keenan and Terrence Branno for their effort of keeping the CPAN
1174tidier by making L<List::Utils> obsolete.
1175
1176Brian McCauley suggested the inclusion of apply() and provided the pure-Perl
1177implementation for it.
1178
1179Eric J. Roode asked me to add all functions from his module C<List::MoreUtil>
1180into this one. With minor modifications, the pure-Perl implementations of those
1181are by him.
1182
1183The bunch of people who almost immediately pointed out the many problems with
1184the glitchy 0.07 release (Slaven Rezic, Ron Savage, CPAN testers).
1185
1186A particularly nasty memory leak was spotted by Thomas A. Lowery.
1187
1188Lars Thegler made me aware of problems with older Perl versions.
1189
1190Anno Siegel de-orphaned each_arrayref().
1191
1192David Filmer made me aware of a problem in each_arrayref that could ultimately
1193lead to a segfault.
1194
1195Ricardo Signes suggested the inclusion of part() and provided the
1196Perl-implementation.
1197
1198Robin Huston kindly fixed a bug in perl's MULTICALL API to make the
1199XS-implementation of part() work.
1200
1201=head2 Jens Rehsack
1202
1203Credits goes to all people contributing feedback during the v0.400
1204development releases.
1205
1206Special thanks goes to David Golden who spent a lot of effort to develop
1207a design to support current state of CPAN as well as ancient software
1208somewhere in the dark. He also contributed a lot of patches to refactor
1209the API frontend to welcome any user of List::MoreUtils - from ancient
1210past to recently last used.
1211
1212Toby Inkster provided a lot of useful feedback for sane importer code
1213and was a nice sounding board for API discussions.
1214
1215Peter Rabbitson provided a sane git repository setup containing entire
1216package history.
1217
1218=head1 TODO
1219
1220A pile of requests from other people is still pending further processing in
1221my mailbox. This includes:
1222
1223=over 4
1224
1225=item * delete_index
1226
1227=item * random_item
1228
1229=item * random_item_delete_index
1230
1231=item * list_diff_hash
1232
1233=item * list_diff_inboth
1234
1235=item * list_diff_infirst
1236
1237=item * list_diff_insecond
1238
1239These were all suggested by Dan Muey.
1240
1241=item * listify
1242
1243Always return a flat list when either a simple scalar value was passed or an
1244array-reference. Suggested by Mark Summersault.
1245
1246=back
1247
1248=head1 SEE ALSO
1249
1250L<List::Util>, L<List::AllUtils>, L<List::UtilsBy>
1251
1252=head1 AUTHOR
1253
1254Jens Rehsack E<lt>rehsack AT cpan.orgE<gt>
1255
1256Adam Kennedy E<lt>adamk@cpan.orgE<gt>
1257
1258Tassilo von Parseval E<lt>tassilo.von.parseval@rwth-aachen.deE<gt>
1259
1260=head1 COPYRIGHT AND LICENSE
1261
1262Some parts copyright 2011 Aaron Crane.
1263
1264Copyright 2004 - 2010 by Tassilo von Parseval
1265
1266Copyright 2013 - 2017 by Jens Rehsack
1267
1268All code added with 0.417 or later is licensed under the Apache License,
1269Version 2.0 (the "License"); you may not use this file except in compliance
1270with the License. You may obtain a copy of the License at
1271
1272 http://www.apache.org/licenses/LICENSE-2.0
1273
1274Unless required by applicable law or agreed to in writing, software
1275distributed under the License is distributed on an "AS IS" BASIS,
1276WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1277See the License for the specific language governing permissions and
1278limitations under the License.
1279
1280All code until 0.416 is licensed under the same terms as Perl itself,
1281either Perl version 5.8.4 or, at your option, any later version of
1282Perl 5 you may have available.
1283
1284=cut
1285
1286120µs1;