Hi, I am not sure if this is the best or even recommended way, but I would use a (global) Dict to store the data. You could use the filename as a key and in your loading function check via haskey if the data is already in the Dict, otherwise you load it as before and add it to the Dict.
Hope that makes sense, Alex. On Thursday, 9 October 2014 10:08:23 UTC+2, > > A beginner's question... > > I'm writing a function that wants to load a set of data from a file, > depending on an argument passed to the function (so a different argument > requires a different set of data to be loaded). I'd like each set of data > to be stored somehow in separate variables so that when the function is > called again with the same argument, it doesn't have to load that > particular data again (because it takes 5 seconds to load). > > I'm not sure whether this requires the use of global variables? I looked > through the documents ( > http://julia.readthedocs.org/en/latest/search/?q=global) but didn't gain > enlightenment. :) > > I think I can test for the existence of a previously-defined variable > using: > > if !isdefined(symbol(string(dataset))) > dataset = include("$(dataset).jl") > end > > but I'm not convinced this works correctly, because this creates a > variable inside the function... > >
