You are on page 1of 1

Play Around!

1. Our TutorialConfig.pm module could use a method that will write a new configuration file to any filename you desire. Write your own write() method (use keys %$self to get the keys of the object's properties). Be sure to use or to warn if the file couldn't be opened! 2. Write a BankAccount.pm module. Your BankAccount object should have deposit, withdraw, and balance methods. Make the withdraw method fail if you try to withdraw more money than you have, or deposit or withdraw a negative amount of money. 3. CGI.pm also lets you use objects if you want. (Each object represents a single CGI query.) The method names are the same as the CGI functions we used in the last article:
use CGI; $cgi = new CGI; print $cgi->header(), $cgi->start_html(); print "The 'name' parameter is ", $cgi->param('name'), ".\n"; print $cgi->end_html();

Try rewriting one of your CGI programs to use CGI objects instead of the CGI functions. 4. A big advantage of using CGI objects is that you can store and retrieve queries on disk. Take a look in the CGI.pm documentation to learn how to use the save() method to store queries, and how to pass a filehandle to new to read them from disk. Try writing a CGI program that saves recently used queries for easy retrieval.

You might also like