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


Monks =P,

For my current project I had a need for a bit of a involved data structure, i.e. a hash of hashes that contains arrays i.e.

thing1: item1: [banana] item2: [pineapple, kiwi, grapes] thing2: item1: [apple, pear]

an example of one of the lines that is giving this response is....

foreach my $clientcode ( @{%client_list{$session}}->{clientrate}} ) {

now I have the whole thing working nicely, however I am getting a message that ...

Using a hash as a reference is deprecated at ./test.pl line 258

...when trying to acess elements of the inner array.

At the moment I've just turned warnings off and left strict on, but it bugs me not to has the latest acess methodology. I'm using perl 5.8.4 atm. If someone could enlighten me as to the correct access method that would be great =).

Regards Paul

Replies are listed 'Best First'.
Re: deprecated access method
by Happy-the-monk (Canon) on Oct 24, 2004 at 22:18 UTC

    @{ %client_list{$session}}->{clientrate}}

    should probably be
    @{ $client_list{$session}->{clientrate} }

    Cheers, Sören


      Sören,

      I just realised I didn't do my self any favours when making a typo (missing bracket)while transcribing it from my linux box, it was supposed to look like

      @{%{$client_list{$session}}->{$clientrate}}

      However you advice worked and looks a lot nicer than the way I way trying.


      Thanks =)
Re: deprecated access method
by Golo (Friar) on Oct 24, 2004 at 22:25 UTC
    my %client_list = ( 1 => { clientrate => ['banana', 'apple'] } + ); my $session = 1; foreach my $clientcode ( @{$client_list{$session}->{clientrate}} ) { print $clientcode; }
    gives no warnings

    changed the %client_list to $client_list and removed the right curly behind $session.
    update:to slow ... *grr*