Re: Using a hash as a reference is deprecated

On Mar 9, 3:21 pm, "bernie" <bernie.g...@xxxxxxx> wrote:
I am new to Perl and I am responsible for maintaining a legacy system
and I would like to understand way these is causing "Using a hash as a
reference is deprecated" and how to stop it,

Stop using a hash in a context where what is needed is a reference to
a hash.

The foreach $tab_ttc (@{%{$tab_h}->{$tab}->{TTC}}) { is the line where
causing warning.

Actually with a bit of experimentation you could have reduced the part
of the code causing the problem to:


When you have...


....the bit (some_expression) evaluated in a scalar context must return
a reference to a hash (or at least something that can behave as one).

In your code it doesn't. scalar(%{$tab_h}) should return the bucket
usage stats for the hash. (Oddly this will change in Perl6).

Unfortunately due to a bug in and early versions of Perl 5.x the Perl
compiler will compile the erroneous code...


.... as if you'd simply said...


....which is probably what you meant anyhow.

Worse still this compiler bug hung about long enough that a lot of
people released code with this mistake in it. So rather than just fix
the compiler bug and break all these programs it was decided to keep
the bug (at least for a few versions of Perl) but emit a warning.

Since in Perl6 the rules will have changed completely anyhow I suspect
that the bug will never be removed in Perl5 and it'll always just be a

I would apporate any help you can provide.

Perl already comes with extensive help documents. You should always
look there for help before looking elsewhere. The document that
explains the meanings of warnings and errors is called perldiag.