App-pl
view release on metacpan or search on metacpan
pod/examples.pod view on Meta::CPAN
> 0b11111100 0374 252 0xfc 0b11111101 0375 253 0xfd 0b11111110 0376 254 0xfe 0b11111111 0377 255 0xff
=item ISO Paper Sizes
I<ISO replaced 8 standards by one. Now we have 9 standards. :-(>
Since C<@A(RGV)> is initially empty, B<-A> isn't looping. So we can do other
things as a side effect, rather than in a separate B<-B>. Use Perl's lovely
list assignment to swap and alternately halve the numbers. Because halving
happens before echoing, start with double size:
pl -oA '($w, $h) = (1189, 1682); 0..10' \
'form "A%-2d %4dmm x %4dmm", $_, ($w, $h) = ($h / 2, $w)'
pl -oA '($w, $h) = (1189, 1682); 0..10' \
'f "A%-2d %4dmm x %4dmm", $_, ($w, $h) = ($h / 2, $w)'
> A0 841mm x 1189mm
> A1 594mm x 841mm
> A2 420mm x 594mm
> A3 297mm x 420mm
> A4 210mm x 297mm
> A5 148mm x 210mm
> A6 105mm x 148mm
> A7 74mm x 105mm
> A8 52mm x 74mm
> A9 37mm x 52mm
> A10 26mm x 37mm
The table could easily be widened to cover B- & C-formats, by extending each
list of 2, to a corresponding list of 6, e.g. C<($Aw, $Ah, $Bw, ...)>. But a
more algorithmic approach seems better. The format is tripled (with cheat
spaces at the beginning). The main program loops over C<@A(RGV)>, thanks to
B<-O>, doing the same as above, but on anonymous elements of C<@d>, which got
set as a side effect of B<-A>:
pl -OA '@d = (["A", 1189, 1682], ["B", 1414, 2000], ["C", 1297, 1834]); 0..10' \
'form " %3s %4dmm x %4dmm" x 3,
map +("$$_[0]$ARGV", ($$_[1], $$_[2]) = ($$_[2] / 2, $$_[1])), @d'
pl -OA '@d = (["A", 1189, 1682], ["B", 1414, 2000], ["C", 1297, 1834]); 0..10' \
'f " %3s %4dmm x %4dmm" x 3,
map +("$$_[0]$A", ($$_[1], $$_[2]) = ($$_[2] / 2, $$_[1])), @d'
> A0 841mm x 1189mm B0 1000mm x 1414mm C0 917mm x 1297mm
> A1 594mm x 841mm B1 707mm x 1000mm C1 648mm x 917mm
> A2 420mm x 594mm B2 500mm x 707mm C2 458mm x 648mm
> A3 297mm x 420mm B3 353mm x 500mm C3 324mm x 458mm
> A4 210mm x 297mm B4 250mm x 353mm C4 229mm x 324mm
> A5 148mm x 210mm B5 176mm x 250mm C5 162mm x 229mm
> A6 105mm x 148mm B6 125mm x 176mm C6 114mm x 162mm
> A7 74mm x 105mm B7 88mm x 125mm C7 81mm x 114mm
> A8 52mm x 74mm B8 62mm x 88mm C8 57mm x 81mm
> A9 37mm x 52mm B9 44mm x 62mm C9 40mm x 57mm
> A10 26mm x 37mm B10 31mm x 44mm C10 28mm x 40mm
=item ANSI Background;Foreground Color Table
I<What color is a mirror? It depends whom you ask. ;-)>
You get numbers to fill into C<"\e[BGm">, C<"\e[FGm"> or C<"\e[BG;FGm"> to get
a color and close it with C<"\e[m">. There are twice twice 8 different colors
for dim & bright and for background & foreground. Hence the multiplication of
escape codes and of values to fill them.
This fills C<@A(RGV)> in B<-A> twice, the 2nd time looping over the 1st list,
as though it had been given on the command line. It maps it to the 16-fold
number format to print the header, swallowing every other number with 0-width.
Then the main program loops over it pairwise with C<$A(RGV)>, thanks to
B<-o2>, to print the body. Numbers are duplicated with C<(N)x2>, once to go
into the escape sequence, once to be displayed:
pl -o2A 1..8 -A '$_, $_+39, $_+8, $_+99' -B 'form "co: bg;fg"."%4d%.0s"x16, @ARGV;
$b = Form "\e[%dm%3d "x16, map +(($_)x2, ($_+60)x2), 30..37' \
'form "%2d: %4d; \e[%2:dm$b\e[m", @$_'
pl -o2A 1..8 -A '$_, $_+39, $_+8, $_+99' -B 'f "co: bg;fg"."%4d%.0s"x16, @A;
$b = F "\e[%dm%3d "x16, map +(($_)x2, ($_+60)x2), 30..37' \
'f "%2d: %4d; \e[%2:dm$b\e[m", @$_'
=item Terminal Rulers
If you need a ruler to better count the width of some other output, you can
print out one of the following. These are either decimal, by groups of 5 or
hex by groups of 4 and 8. The latter two do the same. But instead of one
static ruler of length 100 or 256, they repeat and adapt. Depending on your
terminal emulator and Shell, the variable C<$COLUMNS> may track the current
width. If so, pass it in a single argument to "loop" over with B<-o>, else
provide the desired width yourself:
pl 'say map "$_...:.....", 0..9'
pl 'say map "$_..:...|...:....", 0..9, "A".."F"'
pl -o 'say substr join( "", map "$_...:.....", 0..9 ) x ($_ / 100 + 1), 0, $_' $COLUMNS
pl -o 'say substr join( "", map "$_..:...|...:....", 0..9, "A".."F" ) x ($_ / 256 + 1), 0, $_' $COLUMNS
> 0...:.....1...:.....2...:.....3...:.....4...:.....5...:.....6...:.....7...:.....8...:.....9...:.....
> 0..:...|...:....1..:...|...:....2..:...|...:....3..:...|...:....4..:...|...:....5..:...|...:....6..:...|...:....7..:...|...:....8..:...|...:....9..:...|...:....A..:...|...:....B..:...|...:....C..:...|...:....D..:...|...:....E..:...|...:....F....
> 0...:.....1...:.....2...:.....3...:.....4...:.....5...:.....6...:.....7...:.....
> 0..:...|...:....1..:...|...:....2..:...|...:....3..:...|...:....4..:...|...:....
=back
=head2 Math
=over
=item Minimum and Maximum
The C<List::Util> functions C<min> and C<max> are imported for you:
pl 'echo max 1..5'
pl 'e max 1..5'
> 5
If you have just several numbers on each line and want their minimums, you can
autosplit (B<-a>) to C<@F(IELD)>:
pl -a 'echo min @FIELD' file*
pl -a 'e min @FIELD' file*
If on the same you just want the overall minimum, you can use the print-at-end
variable C<$R(ESULT)>, which you initialise to infinity in a B<-B> begin
program:
( run in 2.374 seconds using v1.01-cache-2.11-cpan-f56aa216473 )