Please send questions to st10@humboldt.edu .
#!/usr/bin/perl -w

#######################################################
# lect08_eval1
#
# playing a bit with catching errors in an eval block
#
# (see more about eval on pp. 234-236, Ch. 17,
#    "Learning Perl")
#
# modified by Sharon Tuttle from "Learning Perl",
#    by Schartz and Phoenix
#
# last modified: 12-2-04
#######################################################

print "enter value for barney: ";
$barney =  <STDIN>;
print "enter value for fred: ";
$fred =  <STDIN>;
print "enter value for dino: ";
$dino =  <STDIN>;

# CATCH error if a silly person enters 0 for $dino...

# note that eval is an expression, not a control structure,
#    so it NEEDS a semicolon at the end...

eval 
{ 
    $barney = $fred;
    $barney = $fred / $dino ;
    print "LINE PRINTED AFTER DIVIDING FRED BY DINO\n";
};

# $@ is empty if no fatal error was thrown, and filled
#    with the error message if one WAS thrown...

if ($@)
{
    print "you probably tried to divide by 0, naughty! But going on.\n";
    print "\$\@ contains: $@\n";
}
else
{
    print "hey, \$\@ was empty!\n";
    print "fred/dino is barney, now $barney\n";
}

if (defined($barney))
{
    print "\$barney contains: $barney\n";
}
else
{
    print "\$barney is undefined\n";
}

# end of lect14_eval1