[Israel.pm] array 2 hash for quick search

Yuval Yaari yuval at windax.com
Tue Jun 15 01:59:47 PDT 2004


perldoc -q unique
That's good if you want it for unique-ify-ing your array or to check if
an element exists().

  --Yuval

On Tue, 2004-06-15 at 11:51, Shlomo Yona wrote:
> Hello,
> 
> Is there any other idiom for transforming an array to a hash
> for quick search? I'm looking for some short hack.
> 
> sub array2hash {
> 	my ($array) = @_;
> 	my %hash;
> 	foreach my $array_item (@$array) {
> 		$hash{$array_item}++
> 	}
> 	return \%hash;
> }
> 
> Thanks.




More information about the Perl mailing list