[Israel.pm] array 2 hash for quick search

Itamar Elem elem at compugen.co.il
Tue Jun 15 02:05:24 PDT 2004


hi

try

%h = map {$_,1} @l;

-----Original Message-----
From: Shlomo Yona [mailto:shlomo at cs.haifa.ac.il]
Sent: Tuesday, June 15, 2004 11:51 AM
To: perl at perl.org.il
Subject: [Israel.pm] array 2 hash for quick search


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.

-- 
Shlomo Yona
shlomo at cs.haifa.ac.il
http://cs.haifa.ac.il/~shlomo/
_______________________________________________
Perl mailing list
Perl at perl.org.il
http://www.perl.org.il/mailman/listinfo/perl




More information about the Perl mailing list