Passing db path to \l or .Q.l using a variable
Asked Answered
I

3

5

I'm writing a q script that loads a db in a particular path and does some processing on it. The location of the db is currently hardcoded in the script, but I want to pass the db path as an argument and get it to load from the path in the variable.

Currently it looks like this:

q) \l /path/to/dbDir        #Works

I figured out that .Q.l should let us do this using a variable, so I tried using the following in the script,

dbPath:`$.z.x 0
.Q.l hsym dbPath            #Fails

When running with argument /path/to/dbDir, the script always fails with some unreadable stuff and:

':/path/to/dbDir: No such file or directory

Could someone please help?

Ironmonger answered 4/7, 2011 at 13:44 Comment(0)
D
4

.Q.l is synonymous with \l which only takes a single argument, which is not an hsym but a file or directory name.

Incidentally the unreadable stuff was the function definition, followed by a type error (as it was not expecting an hsym)

Derril answered 12/7, 2011 at 13:51 Comment(0)
A
5

\x ... is always equivalent to system"x ...", which is the general solution to the "how do i pass a variable to a \ command question

in your case, you want

system"l ",.z.x 0

(btw, i don't think .Q.l is involved in \l of code, only of data, so don't try to use it to load extra .q files)

Arielle answered 23/3, 2012 at 2:49 Comment(0)
D
4

.Q.l is synonymous with \l which only takes a single argument, which is not an hsym but a file or directory name.

Incidentally the unreadable stuff was the function definition, followed by a type error (as it was not expecting an hsym)

Derril answered 12/7, 2011 at 13:51 Comment(0)
I
2

Okay, it seems to work when we try .Q.l without the hsym like this:

dbPath:`$.z.x 0
.Q.l dbPath
Ironmonger answered 6/7, 2011 at 11:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.