# How to define local or global variables?

**URL:** https://discourse.julialang.org/t/how-to-define-local-or-global-variables/69949
**Category:** General Usage
**Tags:** question
**Created:** [October 17, 2021, 9:44pm UTC](https://discourse.julialang.org/t/how-to-define-local-or-global-variables/69949 "2021-10-17T21:44:25Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![leon](https://avatars.discourse-cdn.com/v4/letter/l/dc4da7/32.png) [@leon](https://discourse.julialang.org/u/leon)
#### Post date: [October 17, 2021, 9:44pm UTC](https://discourse.julialang.org/t/how-to-define-local-or-global-variables/69949/1 "2021-10-17T21:44:25Z")

</div>

So far the most frustrating part of using Julia has been the below annoying error message:

`Assignment to `IDOutput` in soft scope is ambiguous because a global variable by the same name exists: `IDOutput` will be treated as a new local. Disambiguate by using `local IDOutput` to suppress this warning or `global IDOutput` to assign to the existing global variable.`

My code:  
`IDOutput = [];`

If I have only a few input parameters, I would wrap everything into a function. But sometimes, I have dozens and dozens of parameters. What is the most grace way of fixing this issue?

Is it even true that “a global variable by the same name exists”? No matter how I change the name to something unique, the system would simply throw out the same error.

---

<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: [October 17, 2021, 10:32pm UTC](https://discourse.julialang.org/t/how-to-define-local-or-global-variables/69949/2 "2021-10-17T22:32:11Z")

</div>

You can just put `let` at the beginning of your script and `end` at the end, and voila: everything is a local variable. (But `using` and `import` and `include` statements must go outside the `let` block.)

But in general the way to deal with passing lots of parameters is to define one or more `struct` types encapsulating them. (Or use a named tuple, which is essentially a `struct` without a name.) Coming up with good data structures and abstractions is hard, but the payoffs in long run (for maintainability, flexibility, composability, and performance) are huge.

---

<div class="post-metadata">

### Author: ![leon](https://avatars.discourse-cdn.com/v4/letter/l/dc4da7/32.png) [@leon](https://discourse.julialang.org/u/leon)
#### Post date: [October 17, 2021, 10:36pm UTC](https://discourse.julialang.org/t/how-to-define-local-or-global-variables/69949/3 "2021-10-17T22:36:18Z")

</div>

Many thanks for sharing the below trick. It works!

```julia
let
...
end

```
