Here are the I/O routines:
POKI_INCLUDE_ESCAPED(polyglot-dkvp-io/dkvp_io.py)HERE
And here is an example using them:
POKI_RUN_COMMAND{{cat polyglot-dkvp-io/example.py}}HERE
Run as-is:
POKI_RUN_COMMAND{{python polyglot-dkvp-io/example.py < data/small}}HERE
Run as-is, then pipe to Miller for pretty-printing:
POKI_RUN_COMMAND{{python polyglot-dkvp-io/example.py < data/small | mlr --opprint cat}}HERE
Here are the I/O routines:
POKI_INCLUDE_ESCAPED(polyglot-dkvp-io/dkvp_io.rb)HERE
And here is an example using them:
POKI_RUN_COMMAND{{cat polyglot-dkvp-io/example.rb}}HERE
Run as-is:
POKI_RUN_COMMAND{{ruby -I./polyglot-dkvp-io polyglot-dkvp-io/example.rb data/small}}HERE
Run as-is, then pipe to Miller for pretty-printing:
POKI_RUN_COMMAND{{ruby -I./polyglot-dkvp-io polyglot-dkvp-io/example.rb data/small | mlr --opprint cat}}HERE
The
system DSL function allows you to run a specific shell command and put its output — minus the final newline — into a record field. The command itself is any string, either a literal string, or a concatenation of strings, perhaps including other field values or what have you.
POKI_RUN_COMMAND{{mlr --opprint put '$o = system("echo hello world")' data/small}}HERE
POKI_RUN_COMMAND{{mlr --opprint put '$o = system("echo {" . NR . "}")' data/small}}HERE
POKI_RUN_COMMAND{{mlr --opprint put '$o = system("echo -n ".$a."| sha1sum")' data/small}}HERE
Note that running a subprocess on every record takes a non-trivial amount of time. Comparing asking the system
date command for the current time in nanoseconds versus computing it in process:
POKI_RUN_COMMAND{{mlr --opprint put '$t=system("date +%s.%N")' then step -a delta -f t data/small}}HERE
POKI_RUN_COMMAND{{mlr --opprint put '$t=systime()' then step -a delta -f t data/small}}HERE