Why does Perl warn me about using pseudo hashes?

Perl warns me about using pseudo hashes in my program:

Pseudo hashes are out of date

How can I convert the following code so that it does not use pseudo hashes

foreach my $hash (@arrayOfHash) { print keys %{$hash}; } 
+4
source share
2 answers

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

If for some reason you cannot fix @arrayOfHash , you can work around this by doing:

 foreach my $hash (@arrayOfHash) { my %hash = @$hash; print keys %hash; } 
+10
source

You should always post the full example code.

Not sure what you are doing, but you are probably mixing arrays and arrays of refs and / or hashes and hashrefs. I usually use only links, since 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 
+5
source

All Articles