Altering Control Flow

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.

last

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>; ...

Get Programming PERL in the .NET Environment now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.