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.
Loops or conditional branching statements; but, not used together.
- Generate and display the numbers from 1 to 10. Now, print them along with their
- Read in an array of numbers. Print the count of the numbers entered, their sum,
and the sum of their squares.
- 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.
- Echo "odd" or "even" based on the number of arguments to the script.
- Count down from the number of arguments on the command line to zero.
- Echo each argument given on the command line.
- Check the first argument passed to the script and print whether it is a file or a
- Compare the first three arguments as text strings and print which ones differ.
- Convert text month names to numeric month numbers, e.g. "Jan" to
- Convert numeric months to text months, e.g. "1" to "Jan".
- 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.
- Copy standard input to standard output, adding line numbers.
- Split standard input into individual words, one per line.
- 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).
- Create a table of imaginary Microsoft products and ratings in your program. Prompt
the user to enter a product name; print the corresponding rating.
- Using Perl directory functions, produce a sorted list of all file names in the current
- Produce a sorted list of file names from each directory given on the command line.
- 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.)
Combining loops and conditional statements.
- Read in two arrays. Loop over the arrays, comparing them element-by-element and
printing the elements that differ, along with their index numbers.
- 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.
- Count the number of files and directories given on the command line.
- Print the names and sizes of all pathnames given on the command line that are files and
that exceed a given size.
- 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.
- 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.
- 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).
- Accumulate and print a running total of the sizes of all files given as command line
- 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.
- 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.)
- 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.
- Print the number of unique words in standard input, along with a count of how
often each word occurs in the input.
- 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.
- 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).
- 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.
- 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
- Prompt for a pathname to a directory. Open that directory and find and display all
file names beginning with "customer".
- 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
- 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:
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.)
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.
|c foo - create a file
|d foo - delete a file
|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
Sophisticated use of loops and conditional statements.
- 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).
- 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
- 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.
- 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".
See the entries for Perl and Basic Programming in the FastTrack Resources