in reply to Why do I need a slash before my -- \my -- in getopts

First, a primer

{ ... } creates a new (anonymous) hash. The hash is initialized using the specified list. A reference to the new hash is returned.

\%hash simply returns a reference to the specified hash.

Now, in context

{ my %opts } first creates hash %opts. Then it creates a new (anonymous) hash. The anonymous hash is initialized with the contents of %opts (which is empty). A reference to the anonymous hash is returned (and passed to getopts).

That doesn't work because getopts populates the anonymous hash, which is freed as soon as getopts returns because you never saved a reference to it. And %opts is left untouched because getopts doesn't know it exists.

When you use \%opts, on the other hand, you pass a reference to %opts, so getopts populates %opts

Fletch covered the role of my in his post.