Get me out of this while loop( perl regexp)
Guys,
Get me out of the while loop I am using in the code which is: Code:
#find the no. of occurences of a word in the given line |
Quote:
... For starters, have you actually thought about the validity of this: Code:
(defined $f) != " " |
Sergei Steshenko,
I don't really get you what you are trying to say!! |
Quote:
After answering the above question try again to answer the question I've asked: Quote:
|
Quote:
|
Quote:
The thing that is wrong from the very beginning is lack of debugging skills. What you are doing is conceptually this: Code:
while(<condition>) So, why should anybody guess why <condition> doesn't go false ? Why don't you make the effort yourself and and print the condition ? I.e. why don't you change your code to become, say: Code:
while(<condition>) Code:
for(my $attempt_number = 0; $attempt_number < 5; $attempt_number++) Then analyze what is printed and fix the problem. |
And why don't you use
Code:
use strict; |
Quote:
Quote:
For your kind information here is the code where I used some debugging skills Code:
#print $f; Quote:
|
Quote:
Every bug reporting guidelines demand publishing log files/screen output when they are available. In your case screen output can definitely be made available. |
Quote:
I am presenting in front of you the entire input/output and source files. Firstly the source file: Code:
#find the no. of occurences of a word in the given line Code:
[Ashok@station130 My Work]$ perl temp.pl Now I think this information is more than enough for you and its your turn now. |
Quote:
As I said, the problem is debug skills, and, in this case, poor way to display a variable with text contents. The point is that text can also contain whitespaces, and you made no effort to implement your print statements in a manner than shows whitespaces. So, for starters, assuming that your input data does not contain '|' character, please do the following:
and publish the screen output again. |
Hi,
Here's a solution for your problem, based on your original code: Code:
#!/usr/bin/perl It is up to you to figure out why the above code works and yours did not (you do want to learn something, don't you?). Anyway, hope this helps. |
Quote:
Arrrrgh, you spoiled such a nice party :). |
@Sergei Steshenko: LOL.
I do hope that the OP doesn't just copy/paste that line, but understands why this needs to be implemented this way. But like I stated before, that is up to him. I also hope that it is clear to the OP why strict/warnings are needed in the code. |
I am really enjoying this guys.
I think your code really works for only some inputs. But what about this input? Code:
[Ashok@station130 My Work]$ perl temp.pl |
All times are GMT -5. The time now is 10:25 PM. |