ACCC Home Page ACADEMIC COMPUTING and COMMUNICATIONS CENTER
Accounts / Passwords Email Labs / Classrooms Telecom Software Computing and Network Services Education / Teaching Getting Help
 
Seminar - Perl II
0. Contents 1. Intro 2. Sources 3. Special Variables 4. Subroutines 5. Regexp
6. Ties & DBM 7. Functions 8. Eval 9. Larger Example 10. Exercises  

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.
 
 

Perl II Previous: 9. Larger Example


1999-4-7  BobG
UIC Home Page Search UIC Pages Contact UIC