perl - Is hashref in array?

Andrew Jorgensen andrew.jorgensen at
Tue Jan 9 17:05:50 MST 2007

Hi folks,  I'm trying to figure out a slick way to find out if a
particular hashref is in an array of hashrefs.  Also acceptable would
be to extract only the unique elements from an array of hashrefs.

I've tried the examples in perlfaq for both of those questions but the
answers leave me with strings that look like this, HASH(0x8148b44),
rather than actual hashrefs.

So is there a slick way to do this?  Or, alternatively, is there a way
to convert that string back into a real hashref?

Below is some test code of one attempt that just leaves me with the strings:

Thanks in advance for your ideas!

- Andrew Jorgensen

use strict;
use warnings;
use Data::Dumper;

my @tree;
my $zero = { a => "0", b => "0" };
my $one = { a => "1", b => "1" };

push @tree, $zero, $one, $zero, $one;

my %saw;
@saw{@tree} = ();
my @out = keys %saw;

print Dumper(@out);

More information about the PLUG mailing list