Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi!!! i want to compare elements of an array with the contents of a file, and get the line number from the file..... so, to do this i created a hash which hav each line of file as values of hash and line number as key....similarly i converted array to an hash ....... now if i compare the two values to don't get the complete match , an it gets chunk for some lines... $a eq $b,does'nt return me all the matches... can any one giv me an efficient way of doing such comparisions.. Thanx!!!!!!

Replies are listed 'Best First'.
Re: matching values of two hashes
by moritz (Cardinal) on Sep 09, 2008 at 10:46 UTC
    When you want to compare lines, it would make sense to use the line contents as hash keys, not the line numbers. (When you use line numbers as hash keys you can take an array instead in the first place).

    A small sample of both input and desired output data would help to better and easier understand your problem.

    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: matching values of two hashes
by perlplayer (Sexton) on Sep 09, 2008 at 11:04 UTC
    i think the problem you are facing is due to the fact that though for the programmer the values are entered in a sorted way but inside the hash values and their corresponding keys are stored in random sequence so it is very much possible that inside the hash the no 1 key value pair is not at all what you are expecting.