[EMAIL PROTECTED] wrote:

On Mar 30, 6:54 am, [EMAIL PROTECTED] (John W. Krahn) wrote:

die() exits the program.

Yes, I understand that die() exits the program.  My question was are
you able to process more than one line of code in a die() context?

die(), like print() and warn(), prints a list of strings. To do what I think you are trying to do:

open my $FH, '<', 'somefile' or do {
    # some statement here;
    # and another statement;
    # and finally;
    die "some string here";
    };


Since I didn't know the answer to that, I set my $ExitStatus varialbe
to $EX_NOINPUT so that I would be able to process more than one line
of code before `die`ing.

[ SNIP ]

 You are using the $! variable six statements away from the open()
statement which means that there is no guarantee that its value will be
related to what open() may have set it to.

Yes, but I'm doing nothing between the open() and where I use it that
should cause it to be changed.

You have print() six times, any one of which could change the value of $!.


 Plus, if you look at the output from
the run of my script, you can see that it is reporting the correct
error.  However, you bring up a good point regarding the distance, so
I am going to make the next line after the open() statement an
assignment to a variable to hold that exit error, just in case.

Pass the exit code to your subroutine:

        my $ExitStatus = shift;

What does `shift` do?

With no arguments, in file scope it removes an element from the beginning of the @ARGV array, in subroutine scope it removes an element from the beginning of the @_ array. The @_ array holds the list of scalars that was passed to the subroutine.

perldoc -f shift
perldoc perlsub


And, how does the line `my $ExitStatus = shift;`
pass the exit code to my subroutine?

If you call the subroutine with the exit code as the first argument, for example:

ExitScript( $EX_USAGE );



John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order.                            -- Larry Wall

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to