in reply to Re: Reading two text files parallelly...
in thread Reading two text files parallelly...
A common use for this is in user prompting loops. Putting the prompt together with the ending condition solves the problem of "how to get the loop started" and at the same time puts the condition that is going to stop the loop right up there where it belongs - right in the statement that runs the loop - not buried somewhere in the "guts".
Here is an example. We are asking about part numbers. The user prompt is clear. What stops the loop is clear (q,Q,QuIT, etc) and it is right there where it is supposed to be, in the controlling loop statement. In the "guts" of the loop there will be many error messages like "hey, dummy a part number needs 10 digits" or whatever, followed by a "next;" statement - that restarts the loop and re-prompts the user.
Some would argue that it is better to move the ending condition into the loop and make it the first statement. Well ok thats one way. In that case we have:while ( (print "Enter Part No and Qty: "), (my $line=<STDIN>) !~ /^\s*q(uit)?\s*$/i ) {...}
last if $line !~/^\s*q(uit)?\s*$/i;
I would argue against that as "do forever" loops should be reserved for servers, GUI event loops and such.
In any event, the OP doesn't appear to be in need of such things.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^3: Reading two text files parallelly...
by Hugmeir (Sexton) on Nov 09, 2010 at 19:15 UTC | |
by Marshall (Canon) on Nov 11, 2010 at 16:48 UTC |