.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.43) .\" .\" 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 >0, 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::Maker 3pm" .TH List::Maker 3pm "2022-11-19" "perl v5.36.0" "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::Maker \- Generate more sophisticated lists than just $a..$b .SH "VERSION" .IX Header "VERSION" This document describes List::Maker version 0.005 .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 1 \& use List::Maker; \& \& @list = <1..10>; # (1,2,3,4,5,6,7,8,9,10) \& \& @list = <10..1>; # (10,9,8,7,6,5,4,3,2,1) \& \& @list = <1,3,..10>; # (1,3,5,7,9) \& @list = <1..10 x 2>; # (1,3,5,7,9) \& \& @list = <0..10 : prime N>; # (2,3,5,7) \& @list = <1,3,..30 : /7/>; # (7,17,27) \& \& @list = < ^10 >; # (0,1,2,3,4,5,6,7,8,9) \& @list = < ^@array >; # (0..$#array) \& \& @words = < a list of words >; # (\*(Aqa\*(Aq, \*(Aqlist\*(Aq, \*(Aqof\*(Aq, \*(Aqwords\*(Aq) \& @words = < \*(Aqa list\*(Aq "of words" >; # (\*(Aqa list\*(Aq, \*(Aqof words\*(Aq) \& \& \& use List::Maker \*(Aqlistify\*(Aq; \& @list = listify \*(Aq1..10\*(Aq; # (1,2,3,4,5,6,7,8,9,10) \& \& use List::Maker \*(Aqmake_list\*(Aq; \& @list = make_list \*(Aq10..1\*(Aq; # (10,9,8,7,6,5,4,3,2,1) \& \& use List::Maker \*(Aqql\*(Aq; \& @list = ql\*(Aq1..10 x 2\*(Aq; # (1,3,5,7,9) .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" The List::Maker module hijacks Perl's built-in file globbing syntax (\f(CW\*(C`< *.pl >\*(C'\fR and \f(CW\*(C`glob \*(Aq*.pl\*(Aq\*(C'\fR) and retargets it at list creation. .PP The rationale is simple: most people rarely if ever glob a set of files, but they have to create lists in almost every program they write. So the list construction syntax should be easier than the filename expansion syntax. .PP Alternatively, you can load the module with an explicit name, and it creates a subroutine of that name that builds the same kinds of lists for you (leaving the globbing mechanism unaltered). .SH "INTERFACE" .IX Header "INTERFACE" Within any file in which the module has been explicitly loaded: .PP .Vb 1 \& use List::Maker; .Ve .PP angle brackets no longer expand a shell pattern into a list of files. Instead, they expand a list specification into a list of values. .PP Under Perl 5.10 and later the module is also lexically scoped in its effects. That is, under Perls that support it, the change in the behaviour of angle brackets is confined to the specific lexical scope into which the module was imported. .PP Under Perl 5.8 and earlier, loading the module changes the effect of \f(CW\*(C`<...>\*(C'\fR and \f(CW\*(C`glob()\*(C'\fR for the remainder of the current package in the current file. .PP This means: .PP .Vb 8 \& # Code Under 5.8 or earlier Under 5.10 or later \& ==================== ==================== =================== \& @list = <1..10>; normal glob() normal glob() \& { \& use List::Maker; installs in file installs in block \& @list = <1..10>; generates list generates list \& } \& @list = <1..10>; generates list normal glob() .Ve .SS "Numeric lists" .IX Subsection "Numeric lists" Numeric list specifications may take any of the following forms: .PP .Vb 7 \& Type Syntax For example Produces \& ========== =================== =========== =========== \& Count up <1..5> (1,2,3,4,5) \& Count down <5..1> (5,4,3,2,1) \& Count to < ^LIMIT > < ^5 > (0,1,2,3,4) \& Count by <1..10 x 3> (1,4,7,10) \& Count via <1, 3,..10> (1,3,5,7,9) .Ve .PP The numbers don't have to be integers either: .PP .Vb 1 \& @scores = <0.5..4.5>; # same as: (0.5, 1.5, 2.5, 3.5, 4.5) \& \& @steps = <1..0 x \-0.2>; # same as: (1, 0.8, 0.6, 0.4, 0.2, 0) .Ve .SS "Filtered numeric lists" .IX Subsection "Filtered numeric lists" Any of the various styles of numeric list may also have a filter applied to it, by appending a colon, followed by a boolean expression: .PP .Vb 1 \& @odds = <1..100 : \e$_ % 2 != 0 >; \& \& @primes = <3,5..99> : is_prime(\e$_) >; \& \& @available = < ^$max : !allocated{\e$_} > \& \& @ends_in_7 = <1..1000 : /7$/ > .Ve .PP The boolean expression is tested against each element of the list, and only those for which it is true are retained. During these tests each element is aliased to \f(CW$_\fR. However, since angle brackets interpolate, it's necessary to escape any explicit reference to \f(CW$_\fR within the filtering expression, as in the first three examples above. .PP That often proves to be annoying, so the module also allows the candidate value to be referred to using any single uppercase letter (which is replaced with \f(CW\*(C`\e$_\*(C'\fR when the filter is applied. So the previous examples could also be written: .PP .Vb 1 \& @odds = <1..100 : N % 2 != 0 >; \& \& @primes = <3,5..99> : is_prime(N) >; \& \& @available = < ^$max : !allocated{N} > .Ve .PP or (since the specific letter is irrelevant): .PP .Vb 1 \& @odds = <1..100 : X % 2 != 0 >; \& \& @primes = <3,5..99> : is_prime(I) >; \& \& @available = < ^$max : !allocated{T} > .Ve .SS "Randomly selecting from lists" .IX Subsection "Randomly selecting from lists" In addition to (or instead of) specifying a filter on a list, you can also select a specific number of the list's items at random, by appending \f(CW\*(C`:pick\*(C'\fR \fIN\fR to the list specification. .PP For example: .PP .Vb 1 \& $N_random_percentages = <0..100 : pick $N >; \& \& @any_three_primes = <3,5..99> : is_prime(I) : pick 3>; \& \& $one_available = < ^$max : !allocated{T} :pick> .Ve .PP The requested number of elements are picked at random, and without replacement. If the number of elements to be picked is omitted, a single element is randomly picked. .PP You can also pick \fIwith\fR replacement (which is equivalent to rolling some number of M\-sided dice, with one list element on each face), by using \f(CW\*(C`:roll\*(C'\fR instead of \f(CW\*(C`:pick\*(C'\fR: .PP .Vb 1 \& $N_nonunique_random_percentages = <0..100 : roll $N >; \& \& @three_nonunique_primes = <3,5..99> : is_prime(I) : roll 3>; \& \& $one_available = < ^$max : !allocated{T} :roll> .Ve .PP If the number of elements to be rolled is omitted, a single element is randomly rolled (which is exactly the same as randomly picking it). .PP Note that, because each requested \*(L"roll\*(R" is independent, it's entirely possible for one or more values to be selected repeatedly. .SS "String lists" .IX Subsection "String lists" Any list specification that doesn't conform to one of the four pattern described above is taken to be a list of whitespace-separated strings, like a \f(CW\*(C`qw{...}\*(C'\fR list: .PP .Vb 1 \& @words = ; # same as: ( \*(AqEat\*(Aq, \*(Aqat\*(Aq, \*(AqJoe\e\*(Aqs\*(Aq ) .Ve .PP However, unlike a \f(CW\*(C`qw{...}\*(C'\fR, these string lists interpolate (before listification): .PP .Vb 1 \& $whose = q{Joe\*(Aqs}; \& \& @words = ; # same as: ( \*(AqEat\*(Aq, \*(Aqat\*(Aq, \*(AqJoe\e\*(Aqs\*(Aq ) .Ve .PP More interestingly, the words in these lists can be quoted to change the default whitespace separation. For example: .PP .Vb 2 \& @names = ; \& # same as: ( \*(AqTom\*(Aq, \*(AqDick\*(Aq, \*(AqHarry Potter\*(Aq ) .Ve .PP Single quotes may be also used, but this may be misleading, since the overall list still interpolates in that case: .PP .Vb 2 \& @names = ; \& # same as: ( \*(AqTom\*(Aq, \*(AqDick\*(Aq, "$Harry{Potter}" ) .Ve .PP In a scalar context, any string list is converted to the standard English representation: .PP .Vb 3 \& $names = ; # \*(AqTom\*(Aq \& $names = ; # \*(AqTom and Dick\*(Aq \& $names = ; # \*(AqTom, Dick, and Harry Potter\*(Aq .Ve .SS "Perl 6 repetition list operator" .IX Subsection "Perl 6 repetition list operator" List::Maker also understands the Perl 6 \f(CW\*(C`xx\*(C'\fR listification operator: .PP .Vb 1 \& @affirmations = <\*(Aqaye\*(Aq xx 5>; # (\*(Aqaye\*(Aq,\*(Aqaye\*(Aq,\*(Aqaye\*(Aq,\*(Aqaye\*(Aq,\*(Aqaye\*(Aq) .Ve .SS "Random number generation" .IX Subsection "Random number generation" The module understands two syntaxes for generating random numbers. It can generate a random number within a range: .PP .Vb 1 \& $random = < 2r5.5 >; # 2 <= Random number < 5.5 .Ve .PP It can also generate an \*(L"NdS\*(R" dice roll (i.e. the sum of rolling N dice, each with S sides): .PP .Vb 1 \& $roll = < 3d12 >; # Sum of three 12\-sided dice .Ve .PP The dice notation cares nothing for the laws of physics or rationality and so it will even allow you to specify a non-integer number of \&\*(L"fractal dice\*(R", each with an non-integer numbers of sides: .PP .Vb 1 \& $roll = < 3.7d12.3 >; # Sum of three\-point\-seven 12.3\-sided dice .Ve .PP In a list context, the dice notation returns the results of each of the individual die rolls (including the partial result of a \*(L"fractal\*(R" roll) .PP .Vb 2 \& @rolls = < 3d12 >; # (6, 5, 12) \& @rolls = < 3.7d12.3 >; # (6.1256, 5.9876, 12.0012, 0.3768) .Ve .PP The values returned in list context will always add up to the value that would have been returned in a scalar context. .ie n .SS "User-defined syntax via ""add_handler""" .el .SS "User-defined syntax via \f(CWadd_handler\fP" .IX Subsection "User-defined syntax via add_handler" You can add new syntax variations to the \f(CW\*(C`<...>\*(C'\fR format using the \&\f(CW\*(C`add_handler()\*(C'\fR function: .PP .Vb 1 \& add_handler($pattern => $sub_ref, $pattern => $sub_ref...); .Ve .PP Each pattern is added to the list of syntax checkers and, if it matches, the corresponding subroutine is called to furnish the result of the \f(CW\*(C`<...>\*(C'\fR. User-defined handlers are tested in the same order that they are defined, but \fIbefore\fR the standard built-in formats described above. .SH "ALTERNATE INTERFACE" .IX Header "ALTERNATE INTERFACE" If an argument is passed to the \f(CW\*(C`use List::Maker\*(C'\fR statement, then that argument is used as the name of a subroutine to be installed in the current package. That subroutine then expects a single argument, which may be used to generate any of the lists described above. .PP In other words, passing an argument to \f(CW\*(C`use List::Maker\*(C'\fR creates an explicit list-making subroutine, rather than hijacking the built-in \f(CW\*(C`<..>\*(C'\fR and \&\f(CW\*(C`glob()\*(C'\fR. .PP For example: .PP .Vb 1 \& use List::Maker \*(Aqrange\*(Aq; \& \& for (range \*(Aq1..100 x 5\*(Aq) { \& print "$_: $result{$_}\en"; \& } \& \& \& use List::Maker \*(Aqroll\*(Aq; \& \& if (roll \*(Aq3d12\*(Aq > 20) { \& print "The $creature hits you\en"; \& } \& \& \& use List::Maker \*(Aqconjoin\*(Aq; \& \& print scalar conjoin @names; .Ve .SH "DIAGNOSTICS" .IX Header "DIAGNOSTICS" .ie n .IP """Sequence <%s, %s, %s...> will never reach %s""" 4 .el .IP "\f(CWSequence <%s, %s, %s...> will never reach %s\fR" 4 .IX Item "Sequence <%s, %s, %s...> will never reach %s" The specified numeric list didn't make sense. Typically, because you specified an increasing list with a negative step size (or vice versa). .SH "CONFIGURATION AND ENVIRONMENT" .IX Header "CONFIGURATION AND ENVIRONMENT" List::Maker requires no configuration files or environment variables. .SH "DEPENDENCIES" .IX Header "DEPENDENCIES" None. .SH "INCOMPATIBILITIES" .IX Header "INCOMPATIBILITIES" Using this module normally prevents you from using the built-in behaviours of \f(CW\*(C`<...>\*(C'\fR or \f(CW\*(C`glob()\*(C'\fR in any files that directly \&\f(CW\*(C`use\*(C'\fR the module (though files that don't load the module are unaffected). In files that use the module, you would need to use the \&\f(CW\*(C`File::Glob\*(C'\fR module directly: .PP .Vb 1 \& use File::Glob; \& \& my @files = bsd_glob("*.pl"); .Ve .PP Alternatively, export the list maker by name (see \*(L"\s-1ALTERNATE INTERFACE\*(R"\s0). .SH "BUGS AND LIMITATIONS" .IX Header "BUGS AND LIMITATIONS" The lists generated are not lazy. So this: .PP .Vb 3 \& for (<1..10000000>) { \& ... \& } .Ve .PP will be vastly slower than: .PP .Vb 3 \& for (1..10000000) { \& ... \& } .Ve .PP Please report any bugs or feature requests to \&\f(CW\*(C`bug\-list\-maker@rt.cpan.org\*(C'\fR, or through the web interface at . .SH "AUTHOR" .IX Header "AUTHOR" Damian Conway \f(CW\*(C`\*(C'\fR .SH "LICENCE AND COPYRIGHT" .IX Header "LICENCE AND COPYRIGHT" Copyright (c) 2005, Damian Conway \f(CW\*(C`\*(C'\fR. All rights reserved. .PP This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See perlartistic. .SH "DISCLAIMER OF WARRANTY" .IX Header "DISCLAIMER OF WARRANTY" \&\s-1BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE SOFTWARE \*(L"AS IS\*(R" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR, OR CORRECTION.\s0 .PP \&\s-1IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE SOFTWARE\s0 (\s-1INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE\s0), \s-1EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.\s0