Perl Skills
Home Up Stream A Stream B Shell Skills RegExp Skills Perl Skills Resources Using FTP Web Logs Permissions Notes 1 Notes 2 Inodes Unix exploit - PATH

 

Perl Programming Skill Assessment

This Page under development.

Here are some descriptions of programming problems of varying levels of difficulty.   Ths skills to do these problems come from your text Learning Perl.

To succeed in becoming a Web Programmer, you must be able to do all the programs at the level of the Elementary programming problems given here.  You must be able to do most of the Basic scripts.

Elementary

Loops or conditional branching statements; but, not used together.

  1. Generate and display the numbers from 1 to 10.  Now, print them along with their squares.
  2. Read in an array of numbers.  Print the count of the numbers entered, their sum, and the sum of their squares.
  3. Read in an array of strings and an array of numbers.  Print the items in the first array repeated by the numbers in the second array.
  4. Echo "odd" or "even" based on the number of arguments to the script.
  5. Count down from the number of arguments on the command line to zero.
  6. Echo each argument given on the command line.
  7. Check the first argument passed to the script and print whether it is a file or a directory.
  8. Compare the first three arguments as text strings and print which ones differ.
  9. Convert text month names to numeric month numbers, e.g. "Jan" to "1".
  10. Convert numeric months to text months, e.g. "1" to "Jan".
  11. Build a table of integer squares from zero to 100.  Prompt the user to enter a number.  Use the table to find the square roots of those numbers.  If the number entered isn't in the table, tell the user.
  12. Copy standard input to standard output, adding line numbers.
  13. Split standard input into individual words, one per line.
  14. Open an input file and an output file.  Copy the input to the output.  Handle errors (such as file not found, file system full, or no permission).
  15. Create a table of imaginary Microsoft products and ratings in your program.  Prompt the user to enter a product name; print the corresponding rating.
  16. Using Perl directory functions, produce a sorted list of all file names in the current directory.
  17. Produce a sorted list of file names from each directory given on the command line.
  18. Produce a sorted list of unique list of file names from all the directories given on the command line.  (File names appearing in more than one directory are only mentioned once in the output.)

Basic

Combining loops and conditional statements.

  1. Read in two arrays.  Loop over the arrays, comparing them element-by-element and printing the elements that differ, along with their index numbers.
  2. Read in numbers one-at-a-time until the word "done" is found.  Print the count of the numbers entered, their sum, and the sum of their squares.
  3. Count the number of files and directories given on the command line.
  4. Print the names and sizes of all pathnames given on the command line that are files and that exceed a given size.
  5. For all pathnames given on the command line, make sure that if the pathname is an executable file the file must start with "#!/bin/sh", or if the file starts with "#!/bin/sh" the file must be an executable file.  Print a message if neither statement is true.
  6. Compare all the arguments given on the command line and print a message if they are not all the same.  Print the first one that is different.
  7. Check to see that each argument given on the command line is a valid userid (i.e. the user could log in to this machine).
  8. Accumulate and print a running total of the sizes of all files given as command line arguments.
  9. Keep appending the first argument given to the script into a file until the file size is bigger (in bytes) than the second argument to the script.
  10. Rename all the pathnames given on the command line to have a ".bak" extension; but, only if the given pathname does not already have a ".bak" extension and only if a file with that name ending in ".bak" does not already exist.  (Do not create a ".bak.bak" file and do not overwite any existing file.)
  11. From a log of one day of web connections, count the number of connections for each minute of the day and produce an ASCII graph for each minute showing the number of accesses during each minute.
  12. Print the number of unique words in standard input, along with a count of how often each word occurs in the input.
  13. Open a file.  Read in a table of imaginary Microsoft products and ratings.   Prompt the user to enter a product name; print the corresponding rating.
  14. Prompt the user for a file name, F.  Prompt the user for a number, N.  Open and read the input file F and place every Nth line into a new output file with the name F.N., e.g. "happy" and "3" would result in lines 1, 4, 7, ..., etc. going into file "happy.1", lines 2, 5, 8, ..., etc. going into file "happy.2", and lines 3, 6, 9, ..., etc. going into file "happy.3".   Handle errors such as missing input file or no permission to write output file(s).
  15. Write the program that does the reverse of the above.  It will read a file name F and a number N and combine N input files with names F.N into one output file named F.
  16. Write a program that reads from files given as its command-line arguments.  The program reads the first line from each of the files and joins it into the first line of output.  It reads the next line from each of the files and makes that the second line of output, etc.  For example, if file "one" contained ascending numbers and file "two" contained ascending letters, then "./prog one two one" would produce lines like these:

    1 a 1
    2 b 2
    3 c 3

  17. Prompt for a pathname to a directory.  Open that directory and find and display all file names beginning with "customer".
  18. Prompt for a pathname to a directory.  Open that directory and find all file names beginning with "customer-" followed by a number.  For each matching file name, open that file and print all lines from the open file that begin with the exact file name (that begin "customer-" and end with the same number as the file name).
  19. Process a list of file transactions, one per line, that begin with a letter indicating what to do followed by the name of a file:
    c foo            - create a file named foo
    d foo            - delete a file named foo
    a foo line    - add the text "line" (up to the newline) to the end of the file foo
    d foo line    - find the text "line" (up to the newline) in file foo and delete that line (this requires copying the file to a temporary file)
  20. Read lines from standard input and determine whether they are palindromes.  (e.g. Madam, I'm Adam.  Name no one man.  Able was I ere I saw Elba.  Etc.)
  21. Use the dictionary from /usr/dict/words for this.  Prompt and read a short input string.  Remove the non-letter characters, permute all possible combinations of the letters in the input string and see if any of the permutations are actual words.  For example, you might enter "A rag man" and discover that the permutation "anagram" is in the dictionary.

Advanced

Sophisticated use of loops and conditional statements.

  1. Solve all of the Shell Script and Regular Expression problems entirely in Perl (including the calendar program, ASCII graph of file sizes, and Pig Latin generator).
  2. From a log of several weeks of web connections, count the number of connections for each NNN-minute period and produce an ASCII graph for each period showing the number of accesses during that period.   (NNN is a number of minutes given as an argument on the command line.)  For example, to a graph of the file weblog with the connections counted by hours (periods of 60 minutes) you would type:

        $ ./script -60 weblog
  3. Modify the "guestbook" program given in your text to take an optional name text box.  When a name is typed into that box, only display guestbook entires that match that name.
  4. Use the dictionary from /usr/dict/words for this.  Prompt and read a short input string.  Permute the letters in the input string and see if you can make anagrams.   For example, you might discover that "Ian D Allen" is an anagram for "Land Alien" and "Lain an LED", and that "Internet Intranet" is an anagram for "Earn intent IT rent", "Entrant Tern in Tie", and "Errant tine in tent".  For examples of anagrams see: Dictionary Thesaurus Rhyming Quotations Anagrams Computing Dictionaries & Other Online Dictionaries and be sure to check out the Internet Anagram Server Anagram Hall of Fame which includes such beauties as "The Great New York Rapid Transit Tunnel = Giant Work in Street, Partly Underneath".

Additional Resources

See the entries for Perl and Basic Programming in the FastTrack Resources page.