[Israel.pm] array 2 hash for quick search
Shlomo Yona
shlomo at cs.haifa.ac.il
Tue Jun 15 02:10:27 PDT 2004
On Tue, 15 Jun 2004, Yuval Yaari wrote:
> perldoc -q unique
> That's good if you want it for unique-ify-ing your array or to check if
> an element exists().
The reference you gave me is good for solving another
problems than I'm interested in.
> On Tue, 2004-06-15 at 11:51, Shlomo Yona wrote:
> >
> > 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;
> > }
--
Shlomo Yona
shlomo at cs.haifa.ac.il
http://cs.haifa.ac.il/~shlomo/
More information about the Perl
mailing list