|Do you know where your variables are?|
Re: fasta fileby BrowserUk (Pope)
|on Sep 26, 2011 at 22:51 UTC||Need Help??|
There are many problems with your script.
When you read the lines in from the file
They have newlines attached to their ends. And when you store the sequence ID in teh key of the hash:
You have not removed it. But when you read the accession iD from the user:
You did remove the newline. So when you try to compare those two:
They will not match.
BUT ... when you are trying to compare the id entered by the user with the one read from the file, instead of comparing it with the key (ID) of the hash element:
You are comparing it with the sequence (value) of that hash entry:
Which obviously wouldn't work, even if you had removed the newlines from both.
But then, even if you corrected all those problems, there are many other problems with your program.
First you read all the sequences into the hash -- despite that you know you are only looking for one and could stop reading as soon as you've seen that one.
And then you iterate over the hash checking if each of them matches the ID the user entered -- but the whole point of a hash is that you do not need to iterate over it. You can simply look up whether the key you need exists.
Finally, you should take more care over how you format your code. Think of your code as your workbench. If you keep it neat and tidy, you'll find it a lot easier to find what you are looking for.
Also, if you are intending using Perl to do work, rather than as a hobby, I strongly recommend that you take a basic programmers course, or at least work your way through one of the Learning Perl type books available. It would pay you dividends over and over in the long term.
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.