Please place your solutions in the designated files. Your solution to problem 3 should be placed in problem3.txt. You should submit your homework using either 460_submit or 594sl_submit.
  1. Write a Perl file named that contains a function that computes the value of ex by using the formula:
         ex = 1 + (x/1!) + (x2/2!) + (x3/3!) + ...
    The function should take x and the number of terms to use in the computation. If n is the number of terms then the last term used in the computation should be xn/n!. The function's signature should be:
         e(x, n)
    The file should take x and n as command line arguments and print the result. For example:
         bvz% perl 1 10
    Hint: use e, and not exp as your function name. exp is a pre-defined Perl function and perl will get confused if you try to call your function exp.

  2. Write a Perl function named reverse_array that takes a reference to an array and returns a new array with the elements reversed. Requirements for the problem are as follows:

    Here is a sample output:
         UNIX> perl 1 10 20
         20, 10, 1

  3. Write regular expressions to perform each of the following tasks (assume that in each case you are checking against a string):

  4. Write a Perl function named credit that takes a string with a credit card number as input and returns the 4 groups of 4 numbers in an array. You should assume that the number comes in a string and that the groups of 4 numbers may have spaces or dashes (-) between them. It is not necessary however for a group of 4 numbers to have a separator, nor is it necessary to use the same separator in the group. For example '1234 5689-39694858' is valid. If the string is invalid your function should print an error message along with the offending string. Place your function in a file named The script should pass the command line argument to credit and then print out each of the four groups on a separate line. You may assume that you always have the correct number of command-line arguments. Here is a possible execution of
    	perl "6868-3868 54545868"

  5. Write a Perl script named that takes a latitudinal or longitudinal string of the form "DDD.MM.SS.S" and prints it in the form:
         DDD   degrees
          MM   minutes
          SS.S seconds
    Notice that "degrees", "minutes", and "seconds" are left-aligned. The numbers should be right-aligned. For example, the string "" should be printed as:
          50   degrees
           3   minutes
          22.3 seconds
    It is permissable for the string to omit minutes, seconds, or fractional seconds, in which case the value should default to 0. For example, the strings "050", "050.02", "050.02", and "050.02.16" are all valid. You do not need to write a function to implement this script.

  6. Go to the following web-site and do parts 3-5 with the pgm files. Here are a few tips/comments:

  7. Write a program named to count the frequency of selected words in a file and print the words in descending order by word frequency. Words with equal frequency should be printed in alphabetical order. The selected words will be input on the command line. For example, given the file:
    The quick brown fox jumped
    the brown fence and then 
    met joey fox for dinner.
    and the command:
    perl the fox joey dinner
    your script would output:
    fox: 2
    the: 2
    dinner: 1
    joey: 1
    Your program should ignore case (note that "The" and "the" gets the word frequency for "the" to 2) and should strip non-alphanumeric characters (alphanumeric characters are upper/lowercase letters and the numbers 0-9) from the ends of the strings (hence dinner shows up as 1 in the output even though it has a period attached to it in the input).