Browse - programming tips - perl convert array to hashDate: 2011aug25 Language: perl Q. How can I quickly convert an array to a hash? A. Use grep like this: my @a = qw(one two three four); my %h; grep { $h{$_} = 1 } @a; # Convert to hash # Now its easy to see if something is a in the array if (exists $h{three}) { print "Yes, three is present\n"; }
Add a commentSign in to add a comment | Advertisements:
|