September 2002
Intermediate to advanced
496 pages
10h
English
There are often programming situations where you need to perform a lookup within a data structure such as an array. You either find the item for which you conducted the search or you do not. Once you have found the item, you need to exit from the search loop. There are other situations where you also may need to alter control flow from within a loop.
The program below reads a list of hotels from a file. The user is then asked to enter the name of a hotel. The program loops through the list of hotels, trying to find the user's input among the hotels from the file. See the folder Hotels.
% type hotels.pl # # hotels.pl # open(HOTELS, "hotels"); @hotels = <HOTELS>; while(1) { print "enter hotel name "; $hotel = <STDIN>; ...