tags:

views:

167

answers:

2

Perl is warning me about using pseudo hashs in my program:

Pseudo-hashes are deprecated

How do I convert the following code so that is does not use pseudo hashs

    foreach my $hash (@arrayOfHash) {
            print keys %{$hash};
    }
+9  A: 

The problem isn't in that code. The problem is that @arrayOfHash actually contains arrayrefs, not hashrefs.

If for some reason you can't fix @arrayOfHash, you can work around it by doing:

foreach my $hash (@arrayOfHash) {
     my %hash = @$hash;
     print keys %hash;
}
chaos
It's a good thing that it was deprecated then.
Brad Gilbert
"work around it" is a little generous given neither we nor the questioner seems to know what exactly is in @arrayOfHash. First figure that out, then do something about it. Your code will only be helpful in one limited case of error.
ysth
+5  A: 

You should always post the full example code.....

Not sure what you're doing, but you're probably mixing arrays and array refs and/or hashes and hashrefs. I usually only use references, as I like the syntax better and I like to be consistent:

use strict;
use warnings;

my($arrayrefOfHashrefs) = [
            {foo => 'bar',
          bar => 'baz'},
            {Hello => 'world'},
           ];

foreach my $href (@$arrayrefOfHashrefs) {
    print join("\n", keys %$href);
    print "\n\n";
}

will print:

C:\Temp>perl foo.pl
bar
foo

Hello
Joe Casadonte

related questions