Question: Write a PERL program that allows a user to enter lines of text from the keyboard, which look like this: San Diego 85 Each line

Write a PERL program that allows a user to enter lines of text from the keyboard, which look like this:

San Diego 85

Each line should have a city name and a temperature.

There can be any number of white spaces before, after, and in between the words and numbers.

The city name must be all letters (no hyphen, periods...), and can be any mixture of cases (lower and upper cases)

The temperature must be in the range of -99 to 99, and can have a minus sign but no plus sign.

The user enters "quit" (upper or lower case) when done and with any number of white spaces.

Your script will process input lines as follows:

Reject lines with an improper format by giving an error message and re-prompt. If a user enters an empty line (no characters or all white space) simply re-prompt but give no error message.

Format the output lines by removing leading and trailing spaces on the input line, by converting multiple white spaces into one space character, and by uppercasing all letters on the line to upper case.

Add the formatted line to a scalar string variable via string concatenation.

After the user types "quit", show on screen all valid cities and corresponding temperatures, the number of valid cities entered and the average temperature of these cities.

Using the following input:

NeW YoRk CITy 44

San JOSE 66

denver 66 44

St. Louis 55

Los Angeles x5

Cupertino

Anchorage -2

Death VALLEY 112

Quit

The Denver, St. Louis, Los Angeles, Cupertino, and Death Valley lines should be rejected. The output should look like this:

NEW YORK CITY 44

SAN JOSE 66

ANCHORAGE -2

Cities: 3

Average Temperature: 36

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!