[Israel.pm] array 2 hash for quick search

Shlomo Yona shlomo at cs.haifa.ac.il
Tue Jun 15 02:13:35 PDT 2004


On Tue, 15 Jun 2004, David Baird wrote:

> > sub array2hash {
> > 	my ($array) = @_;
> > 	my %hash;
> > 	foreach my $array_item (@$array) {
> > 		$hash{$array_item}++
> > 	}
> > 	return \%hash;
> > }
> 
> %hash = map { $_, 1 } @array;

David and Itamar, thanks.

This is a lot better! :-)

-- 
Shlomo Yona
shlomo at cs.haifa.ac.il
http://cs.haifa.ac.il/~shlomo/



More information about the Perl mailing list