Skip to content

Selecting the equivalent of an array slice in the put DSL #640

Answered by johnkerl
trantor asked this question in Q&A
Discussion options

You must be logged in to vote

Thanks @trantor -- Miller pre-6's lack of arrays and slicing is indeed frustrating. I ended up doing lots of things to make integer-keyed maps fill some gaps but (as you found) it's awkward.

In Miller 5 I think your $host = joinv(mapselect(splitnvx($2,"-"),1,2),"-") is about as good as it gets.

In Miller 6 (using the REPL to interact):

$ mlr repl
Miller v6.0.0-dev REPL for darwin:amd64:go1.16.5
Pre-release docs for Miller 6: https://johnkerl.org/miller6
Type ':h' or ':help' for online help; ':q' or ':quit' to quit.

[mlr] host = "ab-cd-efg-hijk"

[mlr] splita(host, "-")
["ab", "cd", "efg", "hijk"]

[mlr] pieces = splita(host, "-")

[mlr] pieces[1:2]
["ab", "cd"]

[mlr]

So, in short, join…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@trantor
Comment options

@johnkerl
Comment options

Answer selected by trantor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants