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:

%{$tab_h}->{$tab}

When you have...

(some_expression)->{(some_other_expression)}

....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...

%{$tab_h}->{$tab}

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

$tab_h->{$tab}

....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
warning.

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.

.



Relevant Pages

  • RE: IE6 form POST operation sporadic after sp install
    ... causing me a serious headache. ... I've found reference to it in several places now around ... What bug will they think of next! ...
    (microsoft.public.windows.inetexplorer.ie6.browser)
  • Re: hash two keys to one index
    ... What goes into the map are pairs of (reference to key, ... When I insert an object into the hash table, I pass in ... void insert(Object obj, int hash) throws HashTableFull ... int probe = 0; ...
    (comp.lang.java.programmer)
  • Re: Net::SFTP::Attributes
    ... when I ask a simple question on the correct usage of a module I would ... If $subref is specified, for each entry in the directory, $subref will ... be called and given a reference to a hash with three keys: ...
    (comp.lang.perl.modules)
  • Re: hash two keys to one index
    ... What goes into the map are pairs of (reference to key, ... When I insert an object into the hash table, I pass in ... void insert(Object obj, int hash) throws HashTableFull ... int probe = 0; ...
    (comp.lang.java.programmer)
  • Re: Hashes of Hashes
    ... group = STRING ... If I swap the order of the declarations, then all of the keys for the ... hash that is referenced by $Data. ... This is known as a "symbolic reference" - using the ...
    (perl.beginners)