Introductory Perl Exercises

  1. Write a routine that will read in a data file and append a few more lines to it. Create a dummy data file to test it.
  2. Easy one: write a program that takes a command-line argument of a radius and returns the circumfrance of the circle. Add the ability to check for errors in the passed argument. (Is it a number? Is it a non-zero number? Does the argument even exist?)
  3. Write a program that will read in a data file with planetary data and put the data into hashes (one hash for each parameter, such as mass, radius, etc.). Modify the program so that the user calls the program with an argument that is a planet's name and the program then prints out the planet's paramters, correctly labelled and with units.
  4. I have an Excel spreadsheet that contains a count of spam emails I've receieved each day for the past year or so. The first column is the date (formated as the "dd-mon", where dd is a one- to two-digit day of the month and mon is the three-letter mon abbreviation), the second is the spam count, and the third is the expected number of spams based on a linear regression fit to the availible data. I like reading these data into IDL to plot periodically. There's just one problem: I have a lot of other data in there stuck in random places (so many rows have extra columns). Write an IDL routine that will read in this comma-delimited file and save a new file with just the first three columns. For an extra challenege, modify the date so that it's the number of days since New Year's 2003 (so 1 January 2003 would be "1", etc.). Hashes would be useful at this point, by the way.