New module: Debug_Messages

Austin Schutz tex at
Mon Dec 4 15:06:25 CST 2000

	Well I can tell from the number of downloads that people have real
work to do. :-)

	Anyway, I had an idea last weekend that I added to the module in the
form of the following:

	A try() sub that allows you to do error handling quickly, e.g.:

sub drive_to_town() {
  try(get_in_car(), "Can't get in car" ) || return undef;
  try(start_car(), "Can't start car") || return undef;
  try(drive_car(), "Can't drive car") || return undef;

sub(get_in_car()) {
  try(unlock_car_door(), "Can't unlock car" ) || return undef;
  try(sit_in_car(),"Can't sit in car" ) || return undef;

sub sit_in_car() {
  try( $drivers_seat, "There's no drivers seat" ) || return undef;

undef($drivers_seat); # Take it out to reupholster it

unless (defined(drive_to_town()){ eprint(); }

might generate the following stack trace: line 6, package main: main::drive_to_town():
    Can't get in car line 9, package main: main::get_in_car():
        Can't sit in car
        line 12, package main: main::sit_in_car():
            There's no drivers seat

	Anyway, I always spend about half of my time writing perl code
dealing with error conditions, so I think it's handy.


More information about the Pdx-pm-list mailing list