in reply to Why is it matching??
Take a close look at the logic of your code as it stands
(I assume this is what you meant, but if ($_ !=~ [$target_name]) { doesn't do this! And if that use warnings; was really a part of your program, you would know this as you would have recieved error messages something like
my $target_name = 'the quick brown fox'; $_ = 'the quick brown fox jumps over the lazy dog'; if ($_ !=~ [$target_name]) { print 'ok' } Argument "�›¡¡�›ª╫╧çâ†+¢Â¬Ã¢â€¢Â©ÃƒÅ“₧╠╞╧╓" isn't numeric in +numeric ne (!=) at ... Argument "the quick brown fox jumps over the lazy dog" isn't numeric i +n numeric ne (!=) at ...
Disabling warnings and/ or strict doesn't fix your problems, it just stops perl telling you about them.
Putting them back before you post code, just wastes everyone time.
As you've only read 2 lines, we probably haven't reached the end-of-file yet, so we go back to the top and hit the first if condition again.
If you compare your version of this with the code it is based on at Re: Little pattern problem..., you'll see that you have replaced the inner while loop with an if statement. This means that instead of looping, reading new lines and pushing them onto the array until if finds a line that does match the condition, it reads one line, pushes it and then does nothing else.
Suggestion: Go back to the original code, read through it and try and understand how it works before you try to modify it. Then, when you start making changes, leave warnings and strict enabled!. If you make a change and it gives you a warning, try and understand what the warning means and correct it. Add use Diagnostics; may help you to interpret the messages. Correct any such warnings before you move on to making the next change. In the long run, you'll learn faster and achieve your goal much quicker that way.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Why is it matching??
by bioinformatics (Friar) on Sep 11, 2003 at 22:03 UTC | |
by BrowserUk (Patriarch) on Sep 11, 2003 at 22:48 UTC | |
by bioinformatics (Friar) on Sep 12, 2003 at 17:00 UTC | |
by BrowserUk (Patriarch) on Sep 12, 2003 at 17:16 UTC | |
by bioinformatics (Friar) on Sep 16, 2003 at 19:18 UTC | |
by BrowserUk (Patriarch) on Sep 16, 2003 at 20:23 UTC |