Problem with string interpolation (needs parens)

What wrong below ?

julia> eval(parse("$i = readcsv(\"dane_waluty/chfxau_d.csv.txt\")"))
7023×5 Array{Any,2}:
 "Date"          "Open"    "High"    "Low"     "Close"
 "1984-01-09"  12.15     12.15     12.15     12.15
 "1984-01-16"  11.984    11.984    11.984    11.984
 "1984-01-23"  12.249    12.249    12.249    12.249
 "1984-01-30"  11.859    11.859    11.859    11.859
...
 "2017-03-20"   8.14568   8.15433   8.10901   8.11148
 "2017-03-21"   8.10896   8.17156   8.07113   8.08309
 "2017-03-22"   8.08116   8.10821   8.06253   8.07729

julia> i
"chf"

julia> eval(parse("$i = readcsv(\"dane_waluty/$ixau_d.csv.txt\")"))
ERROR: UndefVarError: ixau_d not defined

Paul

As the error message says, you are using ixau_d (in the string interpolation) but it’s not defined.

Also note that you shouldn’t be calling eval(parse(...)) in any case.

1 Like

More specifically, use $(i)xau_d. Without the parentheses, Julia just sees one token: ixau_d. Note that using eval like this is generally not a good solution — it’s confusing, easy to break, and often won’t do what you might expect it to when you move from the REPL to a function.

1 Like

… The issue is too obvious from the syntax highlighting so I didn’t realize that’s what the code is meant to do.