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

#######################################################
# lect06_die2
#
# using die (and opening a file!); also showing die
#    with a newline in its message, and how that
#    keeps the script name and line number from
#    appearing if the die is executed;
#
# modified by Sharon Tuttle from "Learning Perl",
#    by Schartz and Phoenix
#
# last modified: 9-28-04
#######################################################

# let's say that this is supposed to be called with a single
#    argument, the number of lines to be appended to LOG;
#    if the user gives any more or less, we might just decide
#    to stop right then and there:
#
# (since this is a user-error, not something that might need
#    to be debugged, note that we ended the die message with \n)

if (@ARGV != 1)
{
    die "expects exactly 1 argument, the number of lines to append\n";
}

# if get here --- WAS called with exactly one argument;

$logname = $ARGV[0];

if (! open LOG, ">> $logname")
{
    die "Cannot create log file $logname: $!";
}

# if you get here --- $logname WAS opened for appending,
#    and you could now perform that appending using
#    filehandle LOG;

close LOG;

# end of lect06_die2