newdeveloper
newdeveloper

Reputation: 702

Dereference array of hashes in perl. experimental warning

I am getting a warning when accessing my array. This is probably a unperl way to loop but I am teaching myself perl and I am trying different scenarios. I can loop over the %user but didn't know how to loop over the array hash ref?

my %user;
$user{mike}{emp_id} = 1;
$user{john}{emp_id} = 2;
my @user = \%user;

foreach my $value_hash (@users)
{
   #error line
   foreach my $key (keys $value_hash) 
   { 
      foreach my $id (keys %{ $users{$key} }) 
      {
         print "name: $key\t$id: $users{$key}{$id}\n";
      }
  }
  print "\n";
}

Upvotes: 0

Views: 184

Answers (1)

ikegami
ikegami

Reputation: 385897

keys EXPR was an experiemental feature that has already been abandoned and removed.

$ 5.22t/bin/perl -e'my $h = {}; keys $h;'
keys on reference is experimental at -e line 1.

$ 5.24t/bin/perl -e'my $h = {}; keys $h;'
Experimental keys on scalar is now forbidden at -e line 1.

The proper ways to use keys is

keys HASH
keys ARRAY

Replace

keys $value_hash

with

keys %$value_hash

or

keys %{ $value_hash }

You already used it correctly the second time around.

Upvotes: 2

Related Questions