#!/usr/bin/perl use warnings; use strict; use Carp; # useless program written just to demonstrate the confess function # Ivan Novick, May 19, 2009 my $last = 0; for my $i (1..100){ $last = calculate($i, $last); } print "$last\n"; sub calculate{ my $one = shift; my $two = shift; my $sum1 = add($one, $one); my $sum2 = add($two, $two); return add($sum1, $sum2); } sub add{ my $one = shift; my $two = shift; # this function will die and print an error message as well as a stack trace confess("numbers are too high") if ($two > 1000); return $one + $two; }