perl - Is hashref in array?

Hill, Greg grhill at
Wed Jan 10 11:23:15 MST 2007

> > Can't you just do:
> >
> > my %seen = ();
> > my @unique = grep { !$seen{$_}++ } @tree;
> Actually this would be more efficient (and perlish):
> my @unique = do { my %s ; @s{ @trees } = '' ; keys %s };

It would give him strings instead of hash refs, and it would lose the
order.  So, it's totally wrong.  It might be more efficient (which I
would say is debatable), but how is it more "perlish"?  They're both
pretty perlish to me.

> > Or am I missing something?
> Yeah.  He was getting the stringified reference (HASH(0xABCDEF)) as a
> key and he wanted the actual data as a key.  So you have to serialize
> the referenced data for each key and have some way of bringing it back
> as a reference of values.

Right, but in the one I sent, you don't use the keys, they are just used
for duplicate checking.  You get the results from the values of the
array, so hash refs stay hash refs.

He said it worked.


More information about the PLUG mailing list