in reply to Re^2: new to perl : how to match ?
in thread new to perl : how to match ?
Well, there are a few problems. Are you aware that $line is going to keep growing longer as you continue reading the file? So on the first iteration it contains one line of data, and on the second iteration, it contains the data from two lines of the file (but with the \n newline stripped away between the original file's lines). I'm not sure if that's really your intention or not.
Next, you don't need all that ! eof inFILE stuff. In Perl, while( <filehandle> ) is magic enough for all that.
Also, based on your current logic and on the fact that $line keeps getting new data appended to it, as soon as one line in the file matches (triggering the next if conditional), it will continue matching through the rest of the file, from that point forward.
Do you really mean something more like this?
while( my $line = <inFile> ) { chomp $line; next if $line !~ m/data\sto\s(.*?)\s*is/i; # ....the rest of the loop goes here... }
Update:
We really do wish to help, but the problem seems something of a moving target. Please tell us what you're trying to accomplish; I mean the bigger picture, as in "I want to iterate over the lines of a file and do this or do that..." Maybe if we knew what the objective was we could provide a little more meaningful insight.
Dave
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: new to perl : how to match ?
by Sun (Initiate) on Oct 28, 2005 at 08:21 UTC | |
by McDarren (Abbot) on Oct 28, 2005 at 08:53 UTC | |
by Sun (Initiate) on Oct 28, 2005 at 09:24 UTC | |
by 5mi11er (Deacon) on Oct 28, 2005 at 15:02 UTC |