Perl into – exercise

1) Declare an array containing a list of numbers. Write code that produces the sum of the numbers and print it.

Determine the maximum value in the list and print (find out how to sort numerically) .

2) Declare a hash with countries as the hash key and capitals as the hash value.
Write a small script that lists the countries in alphabetical order along with their capitals. Print the sorted countries and their capitals.

3) Declare two hashes, similar to the one in 2, but with different keys /values. Write a script that combines the two hashes into a new hash. Print the keys and values of the combined hash.

4) Take the list defined in 1) and transform it into another list containing the squares of the values. Implement this using the foreach method and again using the map function. Print the transformed list and make sure each method produced the same results.

 

Solution

* note there can be several ways for solving programming questions. The solution here is just one option. If your answers are different, it does not mean you are wrong!

Advertisements
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: