util::argv - optex argument utility modules
optex command -Mutil::argv
This module is a collection of sample utility functions for command optex.
Function can be called with option declaration. Parameters for the function are passed by name and value list: name=value. Value 1 is assigned for the name without value.
In this example,
optex -Mutil::argv::function(debug,message=hello,count=3)
option debug has value 1, message has string "hello", and count also has string "3".
Multiply each arguments. Default count is 2.
% optex echo -Mutil::argv::times(count=3) 1 2 3 1 1 1 2 2 2 3 3 3
Put suffix to duplicated arguments.
% optex echo -Mutil::argv::times(suffix=.bak) a b c a a.bak b b.bak c c.bak
Reverse arguments.
Collect arguments.
% optex echo -Mutil::argv::collect(index=2:4:6) 1 2 3 4 5 6
will print:
2 4 6
Process substitution.
% optex diff -Mutil::argv::proc= '<(date)' '<(date -u)'
Execute filter command for each file. Specify any command which should be invoked for each argument.
% optex diff -Mutil::argv::filter=command='cat -n' foo bar
In this example, foo and bar are replaced by the result output of cat -n < foo and cat -n < bar. The replacement only occurs when the file corresponding to the argument exists.
foo
bar
cat -n < foo
cat -n < bar
Several options are prepared and enabled by request. To enable specific option, use enable function like this to enable --move and --copy options.
-Mutil::argv::enable=move,copy
Parameter :all can be used to enable everything.
-Mutil::argv::enable=:all
You can use alternative names:
-Mutil::argv::enable(move=mymove,copy=mycopy)
These options are converted $<command(param)> notation, where param is offset or offset,length.
$<command(param)>
--move 0 moves all following arguments there, --remove 0 just removes them, and --copy 0 copies them.
--move 0,1 moves following argument (which does not change anything), and --move 1,1 moves second argument (exchange following two).
--move -1 moves the last argument.
--copy 0,1 duplicates the next.
Exchanges following two arguments. This is same as --move 1,1.
optex -Mutil::argv::enable=exch echo --exch foo bar
bar foo
Set input filter for each file argument.
Next command passes the result of the expand filter to the cat -n for each file in the command line.
expand
cat -n
optex -Mutil::argv::enable=filter cat -n --filter=expand a b c
Following options are interface for builtin functions.
To install App::optex, copy and paste the appropriate command in to your terminal.
cpanm
cpanm App::optex
CPAN shell
perl -MCPAN -e shell install App::optex
For more information on module installation, please visit the detailed CPAN module installation guide.