The code I showed is extremely simple because your input file
example is extremely simple. The code I presented will read in a file and will ignore all lines which begin with the string "Number1" because of the next statement. For all other lines which do not begin with "Number1",
the numbers will be stored in an array. The script will generate warnings if there are blank lines (because of the
print).
Your actual file probably has a more complicated structure than your example file, but I can not predict its structure without more information from you.
| [reply] |
thanks, what happens if the if in the 'next' line isn't true.
(If that's a question, then it should be closed with a question mark, incidentally.)
I personally believe that as with any other C<if>, if the condition isn't true, then the statement, i.e. next is not executed. Then, as with (nearly) any other statement, (that it has a statement modifier doesn't change this) control is passed to the following one. Pretty ordinary stuff, as you can see.
(Apologies for replying so late.)
| [reply] [d/l] [select] |
reason I'm asking is because it seems to me we would then break out of the while loop. I don't want to do that, I'd like to still be able to continue on and look for other strings in the file..etc.. | [reply] |
next will not break out of the while loop; last would break out of the loop.
| [reply] |
I personally believe you shouldn't be (mis)guided by what could possibly seem to you, but rather resort to the actual docs, which tell you what that is. Incidentally, YMMV but I personally find "next" very intuitive as a term to suggest that it won't break out of the loop: just as much as "last" is about the fact that it will.
(Apologies for replying so late.)
| [reply] [d/l] |