|
|
Exercises
|
| |
You can't learn perl without writing programs.
Try your hand at these exercises before attending
the next perl seminar.
|
|
| | | |
| |
|
| |
|
|
|
Strings
|
| |
- Write a better mail-merge program.
|
|
| |
|
|
|
Arrays and Regular Expressions
|
| |
- Write a program to check for well-formedness of an xml file.
That is, for every open tag, there should be an explicit end
tag (i.e. for each <p> there should be a </p>)
and the tags must properly nest. Hint: use an array as
a stack with push and pop to hold the state
of tags seen. Use regular
expressions to find the tags, but be careful about case,
and note that tags can span lines.
|
|
| |
|
|
|
Hashes
|
| |
- Take two arrays, and use hashes to find the
union and intersection of the arrays.
- Print the key-value pairs of a hash, sorted
in order of the values. Remember that although keys
must be unique, values might be identical. Handle
the case in which a value might be undef.
|
|
| |
|
|
|
Subroutines
|
| |
- Write a subroutine to take an arbitrary list of filenames.
Open each file, read the contents, strip out all html
tags. If called in list context, return a list
of the contents, but if called in scalar context,
return the concatenated contents.
Handle non-existent or unopenable files gracefully.
If you use die or croak, trap for it using
eval in the calling subroutine.
|
|
| |
|