No I did not mean to say I was finding this way as slow . But It has happened so many times before that there have been better ways to do things which I have been doing and many of them were so commonplace that I am suprised they didnt occur to me .

So I just wanted to make sure I was not goofing again.
Thanks for the reply
Ram




Sudarshan Raghavan wrote:
On Thu, 28 Nov 2002, Ramprasad A Padmanabhan wrote:

Which is the quickest way of converting an array to hash keys

I have an array
@ARRAY = qw ( a b c d e );

# Convert array to hash keys , so can easily check for exists
# The values of the hash are immaterial to me

@HASH{@ARRAY}=@ARRAY;

....
....
foreach (@SOME_OTHER_ARRAY) {
	next if(exists($HASH{$_}));       # This is why I require a hash
.....
....
}


Can I have a faster way than this @HASH{@ARRAY} = @ARRAY;

Why do you think this is slow? Some other options are to use for or map...
I did a benchmark and a hash slice seems to be the fastest. If you don't care about the values you can do this
@HASH{@ARRAY} = ();


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to