<p>I was wrestling with some Perl that uses hash references.</p>

<p>In the end it turned out that my problem was the line:</p>

<pre><code>$myhash{$key} |= {};
</code></pre>

<p>That is, "assign $myhash{$key} a reference to an empty hash, unless it already has a value".</p>

<p>Dereferencing this and trying to use it as a hash reference, however, resulted in interpreter errors about using a string as a hash reference.</p>

<p>Changing it to:</p>

<pre><code>if( ! exists $myhash{$key}) {
  $myhash{$key} = {};
}
</code></pre>

<p>... made things work.</p>

<p>So I don't have a <em>problem</em>. But I'm curious about what was going on.</p>

<p>Can anyone explain?</p>

Try this:
```
```
my %myhash;
$myhash{$key} ||= {};
```
```
You can't declare a hash
element
in a
```
my
```
clause, as far as I know. You declare the hash first, then add the element in.
Edit: I see you've taken out the
```
my
```
. How about trying
```
||=
```
instead of
```
|=
```
? The former is idiomatic for "lazy" initialisation.