Question: Having some trouble adding some keys to a hash, i.e. modifying in a subroutine. Here's my subroutine call:

```
getMissingItems($filename, \%myItems); #myItems is already defined above this

```

and the subroutine itself:

```
sub getMissingItems {
    my $filename = shift;
    my $itemHash = shift;

    #... some stuff

    foreach $item (@someItems) {

        if (not exists $itemHash{$item}) {
            %$itemHash{$item} = 0; 
        }

    }

}

```

I get the error "Global symbol %itemHash requires explicit package name"

How should I be doing this properly? Thanks. 

EDIT - thanks everyone, over this first hurdle. I'm now getting "Can't use string ("0") as a HASH ref while "strict refs" in use." I just want to set the missing key entry to zero

Answer: 
There is no `%itemHash` in scope of your sub, yet you try to use a variable named that.

You mean to access the hash referenced by `$itemHash`, so 

```
if (not exists $itemHash{$item}) {
    %$itemHash{$item} = 0; 
}

```

should be

```
if (not exists $itemHash->{$item}) {
    $itemHash->{$item} = 0; 
}

```

---

By the way, you could simplify that to

```
$itemHash->{$item} //= 0; 

```

(That checks if the element is `defined`, not if it `exists`, but that's probably the same thing in this case.)
To acces a value in a hash reference, use the arrow dereference operator:

```
if (not exists $itemHash->{$item}) {
    $itemHash->{$item} = 0;
}

```