Right way to put code into a function?

Personally, I would let the parser function return all interesting input parameters in a NamedTuple, e.g.:

using TOML

function parser(filename)

    println("PARSING input parameters from '$filename' file")
    input_parameters = TOML.parsefile(filename)
    println()

    (; blob_width = input_parameters["Initial parameters"]["blob_width"],
        blob_height = input_parameters["Initial parameters"]["blob_height"])

end

iparams = parser("input.toml")

println("blob_width = $(iparams.blob_width)")
println("blob_height = $(iparams.blob_height)")

So that all input parameters are collected in one variable (iparams in this case). If you really want to have each input variable in its own variable, this can still be done (using the same parser function as above):

blob_width, blob_height = parser("input.toml")

println("blob_width = $(blob_width)")
println("blob_height = $(blob_height)")
1 Like