# Run parts of other files from a loop

**URL:** <https://discourse.julialang.org/t/run-parts-of-other-files-from-a-loop/75195>\
**Category:** General Usage\
**Tags:** metaprogramming\
**Created:** [January 25, 2022, 7:32pm UTC](https://discourse.julialang.org/t/run-parts-of-other-files-from-a-loop/75195 "2022-01-25T19:32:37Z")\
**Posts on this page:** 1\
**Showing post:** 10

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [January 26, 2022, 12:47pm UTC](https://discourse.julialang.org/t/run-parts-of-other-files-from-a-loop/75195/10 "2022-01-26T12:47:30Z")

</div>

> [@alexdmeyer](#):
>
> Since the analysis is always the same procedure with different inputs for each outbreak, I have one file (like `main.jl` in my MWE) that performs the analysis and ~20 files (like `file1.jl` in my MWE) that define those outbreak-specific inputs.

Maybe use a data format, such as [JSON](https://github.com/JuliaIO/JSON.jl) or [TOML](https://github.com/JuliaLang/TOML.jl) or [YAML](https://github.com/JuliaData/YAML.jl), to define the parameters, rather than code?

(Forcing yourself to `include` parameters into the global namespace is asking for trouble in the long run. e.g. suppose you want to run many simulations in parallel.)

Of course, sometimes you want code to set up the simulation parameters, e.g. if you are running a parameter sweep. But in this case, I would usually recommend organizing things the other way around — have your parameter-generating code call the computational code (as a subroutine in a package) rather than the opposite. As a general principle, writing nontrivial computational code as global “scripts” makes it inflexible and non-reusable in the long run. See also [Organizing code in Julia](https://discourse.julialang.org/t/best-practise-organising-code-in-julia/74362/2).

Here’s a nice excerpt on a related subject from a great (language-agnostic) book I would recommend, [_The Pragmatic Programmer_](https://www.amazon.com/Pragmatic-Programmer-journey-mastery-Anniversary-dp-0135957052/dp/0135957052):

 ![image](https://global.discourse-cdn.com/julialang/original/3X/9/1/91f9a6dece14d950e0cf6b84ec3cbdcbcb13f543.png)

---

_[View the full topic](https://discourse.julialang.org/t/run-parts-of-other-files-from-a-loop/75195)._
