in reply to doubt in string matching.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: here is my program for string matching in a database
by Jenda (Abbot) on Oct 18, 2006 at 01:47 UTC | |
Conversely to what you seem to think you need help all over the place. You should probably dump what you already have and explain properly what are you searching for. Without trying to go into details for the implementation, but explaining what do you want to acomplish. Regarding your code there are several suspicious or inefficient constructs: you see you do not have to know the length of the array to get the last element, just use negative indices if you want to count from the end. Also $m is not a good variable name!
You do not need to introduce the @pats array here, it's perfectly legal to use foreach my $elem (reverse @seqss) {.... I do not realy understand the purpose of this code. It creates an array (@unique) of unique characters from the input in the order of their last occurance in the string and another (@uni) that contains the same characters in the reversed order. Why? And why do you sometimes use @uni and sometimes @unique later? And why do you call that hash %count if it doesn't contain the count of the characters in the input, but rather the index in the @uni array plus one. Why? I have to admit I got lost.
What the heck??? So you are looping through the indices into the @unique array, you get the number of elements in the array which stays the same, you compute the difference between the count and the current index, then you assign one key+value pair (using doublequotes that should definitely NOT be there) and then you loop through that hash? The hash is only going to contain the one key+value pair you just assigned! There is no point whatsoever in the inner loop! Plus you never use the @key and @val arrays you just created in your twisted way. Why is @array2 (another baaaad variable name) an array??? Sorry, I don't understand what are you have done. What I do understand is that you should delete what you have and start anew. And this time by learning the programming language you intend to use and thinking before you type. Sorry if I sound harsh. (BTW, it's either Perl (the language) or perl (the interpreter). Never PERL.) | [reply] [d/l] [select] |