Due Friday, July 22, at the start of class.
Read two input data files containing data about the countries of the world and store the data into useful data structures. Then, ask for user input and print a simple report based on the stored data.
Your script should be divided into two main parts:
There are two separate data files containing country data. The first file is called input-07-country.txt, and looks like this:
ABW : Aruba : Aruba : Latin America & Caribbean ADO : Andorra : Principality of Andorra : Europe & Central Asia AFG : Afghanistan : Islamic State of Afghanistan : South Asia AGO : Angola : People's Republic of Angola : Sub-Saharan Africa ALB : Albania : Republic of Albania : Europe & Central Asia
That is, there are 4 data fields, separated by the string “ : ” (space - colon - space):
The second data file is called input-07-population.txt, and looks like this:
ABW : 1960 : 49205 ABW : 1961 : 50244 ABW : 1962 : 51258 ABW : 1963 : 52224 ABW : 1964 : 53117
There are 3 data fields, separated by the string “ : ” (space - colon - space):
Read both data files and store all of the data in well-considered data structures. Some hints:
my @line_elements = split(' : ', $input_line);
It is the opposite of the
join function: It takes a single
string, and splits the string into separate array elements by removing
any instances of the first argument. It returns the array of elements
found. Look it up on Perldoc, if you want. Yes, technically, the first
argument is a regular expression, but the string argument given above
works just fine for this assignment.
Now that you have data, we can analyze it a bit and produce reports based on user input.
Note: Pick just one of the following reports! They are listed below in roughly increasing order of difficulty.
Ask the user for a year, the calculate the total world population for that year. Sample output:
Calculate world population for what year? 1970 World population in 1970 was 3665297114 (202 countries). Calculate world population for what year?
Ask the user for a country code, start year, and end year. Calculate and display the population growth in that country from the start year to end year, both as an absolute amount and percentage growth; display the short or long name for the country, not the code. Sample output:
Calculate population growth for what country code? JPN Starting in what year? 1970 Ending in what year? 2000 From 1970-2000, Japan grew by 22525000 (21.6%). Calculate population growth for what country code?
Ask the user for a start year and end year. Calculate and display the top N (5–10 is best) countries based on growth (either absolute growth or percentage growth, your pick). Display short or long names for countries, not codes. Sample output:
Starting in what year? 1970 Ending in what year? 2000 From 1970-2000, the following countries grew the most: 468354000 India 444330000 China 88359301 Indonesia 78183086 Brazil 77473000 Pakistan 77120000 United States 71588515 Bangladesh 68374892 Nigeria 47370000 Mexico 41122025 Philippines Starting in what year?
Do the work yourself, consulting reasonable reference materials as needed; any reference material that gives you a complete or nearly complete solution to this problem or a similar one is not OK to use. Asking the instructors for help is OK, asking other students for help is not.
A printout of your code on a single sheet of paper. Be sure to put your own name in the initial comment block of the code. Identifying your work is important, or you may not receive appropriate credit.