in reply to Re^2: Creating hash with my imput
in thread Creating hash with my imput
If by exit you mean exit the loop and continue the script after the loop, you can use the last function to drop out of a loop, something like:
... while($in){ if($in =~ /exit/i){ last; } } # Code will continue here ...
Here we are using a case-insensitive regular expression match to test for the user entering 'exit'. This means that the user can enter 'Exit', 'EXIT', eXiT', etc. and the loop will still terminate.
This may not be necessay, since in my original example, if the user presses the ENTER key without typing anything, the input will be an empty string after chomp() has removed the newline, which, in Perl, evaluates to false, and the loop terminates.
If, on the other hand, you mean exit from the script without, for instance, printing anything like in my original example, just replace last with exit in the example above.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Creating hash with my imput
by rolandomantilla (Novice) on Aug 19, 2011 at 03:02 UTC | |
by kejohm (Hermit) on Aug 19, 2011 at 04:25 UTC | |
by rolandomantilla (Novice) on Aug 19, 2011 at 05:57 UTC | |
by kejohm (Hermit) on Aug 19, 2011 at 08:30 UTC |