Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Does anyone know why this syntax has been deprecated in Perl 5.8?
%hash->{$item_one}{$ip} = $info->{$key};
I'm getting an error stating:

Using a hash as a reference is deprecated at testmodule.pm line 87.

Thanks for the help

Replies are listed 'Best First'.
Re: 5.8 hash as a reference is deprecated??
by adrianh (Chancellor) on Oct 31, 2003 at 13:04 UTC

    Because it's wrong :-) You should be using a hash like a hash

    %hash{$item_one}{$ip}
    $hash{$item_one}{$ip}

    or a hashref like a reference

    $hashref->{$item_one}{$ip}

    The %hash->{} code had undefined behaviour and is now (quite correctly) being deprecated .

        D'oh! Fixed.
Re: 5.8 hash as a reference is deprecated??
by Limbic~Region (Chancellor) on Oct 31, 2003 at 13:05 UTC
    Anonymous Monk,
    By using the % sigil, you mean the entire hash. You probably want to change the % to a $, meaning a specific key.
    If you did want to assign the entire hash to a list of keys and values, you would use something like:
    %{ $hash->{$item_one}{$ip} } = ( key => 'value' );
    I hope this helps - L~R
Re: 5.8 hash as a reference is deprecated??
by pg (Canon) on Oct 31, 2003 at 16:28 UTC

    This was actually deprecated even in versions like 5.6.1, but Perl silently accepted the wrong syntax, and now it starts to print out this message.

    A similar warning is given for array, if you do something like:

    use strict; use warnings; my @a = (1..100); my $aref = \@a; print @aref->[0];